创建books.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book id="1">
<name>冰与火之歌</name>
<author>乔治马丁</author>
<year>2014</year>
<price>89</price>
</book>
<book id="2">
<name>安徒生童话</name>
<year>2004</year>
<price>77</price>
<language>English</language>
</book>
</bookstore>
Java中获取XML文件的内容的解析方式
DOM 解析 (官方)
- 常用的节点类型
节点类型 | NodeType | Named Constant | nodeName的返回值 | nodeValue的返回值 |
---|---|---|---|---|
Element | 1 | ELEMENT_NODE | element name | null |
Attr | 2 |