关于Java读取xml资料的学习
关于Java读取xml文件的学习一.java类?DocumentBuilder?db??dbf.newDocumentBuilder()? ?doc??db.parse(
关于Java读取xml文件的学习
一.java类
- ?
- DocumentBuilder?db?=?dbf.newDocumentBuilder();? ?
- doc?=?db.parse(?
- System.out.println(NodeList?nodeList?=?doc.getElementsByTagName(?
- Node?fatherNode?=?nodeList.item(System.out.println(?
- Node?attribute?=?attributes.item(i);? ?
- System.out.println(+??
- NodeList?childNodes?=?fatherNode.getChildNodes();? ?
- System.out.println(childNodes.getLength());? ?
- Node?childNode?=?childNodes.item(j);? ?
- System.out.println(}? ?
- }? ?
- ?
- }? ?
- ?
- JavaReadXml?parse?=?}? ?
- }???
二.xml文件
- <?xml?version=<person>? ?
- <first>wang</first>? ?
- <last>laohu</last>? ?
- <age><version>中国邮电出版社</version>? ?
- </person>? ?
- <person>? ?
- <first>li</first>? ?
- <last>junjia</last>? ?
- <age><version>清华大学出版社</version>? ?
- </person>? ?
- </book>??
三.输出结果
根元素为:book?
book节点链的长度:2?
父节点为:person?
9?
子节点名为:first相对应的值为wang?
子节点名为:last相对应的值为laohu?
子节点名为:age相对应的值为25?
子节点名为:version相对应的值为中国邮电出版社
来源:http://developer.51cto.com/art/200906/128418.htm