dom4j对xpath的支持很好的方便了对具体某个节点的遍历,使用xpath遍历时,需要jaxen-1.1.1.jar 的支持
</ROWDATA>
@SuppressWarnings({ "unchecked", "unchecked" })
public static void readFile(String fileName) throws Exception{
SAXReader reader = new SAXReader() ;
Document document = reader.read(new File(fileName)) ;
List<Element> list = document.selectNodes("ROWDATA/ROW/DEPTNO") ;
for(Element e :list){
System.out.println(e.getName()+"="+e.getText());
}
//遍历属性 属性名前面加 @
List<Attribute> listAtt = document.selectNodes("ROWDATA/ROW/ENAME/@firstname") ;
for(Attribute att :listAtt){
System.out.println(att.getName()+"="+att.getText());
}
}
}