Jav解析xml
<?xml version="1.0" encoding="GB2312"?>
<data>
<row user="abc" username="abcname" age="26"/>
</data>
public static void main(String[] args) throws Exception {
List<Element> list = new SAXReader().read(new FileInputStream(new File("C:/T.xml"))).selectNodes("//data/row");
for (Element e : list) {
List<DefaultAttribute> attrs = e.attributes();
for (DefaultAttribute attr : attrs) {
System.out.println(attr.getName() + " " + attr.getValue());
}
}
}
//输出:
user abc
username abcname
age 26
需求包:dom4j-1.6.1.jar
-306 KB , jaxen-1.1-beta-6.jar
-238 KB