首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

关于Java读取xml资料的学习

2012-10-09 
关于Java读取xml文件的学习一.java类?DocumentBuilder?db??dbf.newDocumentBuilder()? ?doc??db.parse(

关于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

热点排行