读书人

关于Java读取xml资料的学习

发布时间: 2012-10-09 10:21:45 作者: rapoo

关于Java读取xml文件的学习

一.java类

  1. ?
  2. DocumentBuilder?db?=?dbf.newDocumentBuilder();? ?
  3. doc?=?db.parse(?
  4. System.out.println(NodeList?nodeList?=?doc.getElementsByTagName(?
  5. Node?fatherNode?=?nodeList.item(System.out.println(?
  6. Node?attribute?=?attributes.item(i);? ?
  7. System.out.println(+??
  8. NodeList?childNodes?=?fatherNode.getChildNodes();? ?
  9. System.out.println(childNodes.getLength());? ?
  10. Node?childNode?=?childNodes.item(j);? ?
  11. System.out.println(}? ?
  12. }? ?
  13. ?
  14. }? ?
  15. ?
  16. JavaReadXml?parse?=?}? ?
  17. }???

二.xml文件

  1. <?xml?version=<person>? ?
  2. <first>wang</first>? ?
  3. <last>laohu</last>? ?
  4. <age><version>中国邮电出版社</version>? ?
  5. </person>? ?
  6. <person>? ?
  7. <first>li</first>? ?
  8. <last>junjia</last>? ?
  9. <age><version>清华大学出版社</version>? ?
  10. </person>? ?
  11. </book>??

三.输出结果

根元素为:book?
book节点链的长度:2?
父节点为:person?
9?
子节点名为:first相对应的值为wang?
子节点名为:last相对应的值为laohu?
子节点名为:age相对应的值为25?
子节点名为:version相对应的值为中国邮电出版社
来源:http://developer.51cto.com/art/200906/128418.htm

读书人网 >XML SOAP

热点推荐