dom4j解析XML例子
package com.zuxia.dom4j;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
public class ReaderXML {
public static void main(String[] args) {
//1. 创建解析器
SAXReader reader = new SAXReader();
Document doc = null;
//2. 加载xml文件,获取Document
try {
doc = reader.read("e:/StudentInfo.xml");
} catch (Exception e) {
e.printStackTrace();
}
//3. 获取根节点
Element root = doc.getRootElement();
//根据根节点获取子节点
List<Element> list = root.elements();
for(Element e : list){
System.out.println(e.elementText("name")+"\t"+e.elementText("sex")+"\t"+e.elementText("javascore"));
}
}
}