[size=x-large]前提是将dom4j-1.6.jar添加到项目中。
package com.test;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
public class XmlReader {
public static void main(String[] args) throws Exception {
SAXReader reader=new SAXReader();
Document document=reader.read(new File("E:\\资料\\test.xml"));
Element root=document.getRootElement();
diao(root);
}
public static void diao(Element root){
Iterator it=root.elementIterator();
while(it.hasNext()){
Element e=(Element) it.next();
System.out.println(e.attributeValue("text")+e.attributeValue("roles")+e.attributeValue("url"));
diao(e);
//System.out.println(e.getName());
}
}
}[/size]
package com.test;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
public class XmlReader {
public static void main(String[] args) throws Exception {
SAXReader reader=new SAXReader();
Document document=reader.read(new File("E:\\资料\\test.xml"));
Element root=document.getRootElement();
diao(root);
}
public static void diao(Element root){
Iterator it=root.elementIterator();
while(it.hasNext()){
Element e=(Element) it.next();
System.out.println(e.attributeValue("text")+e.attributeValue("roles")+e.attributeValue("url"));
diao(e);
//System.out.println(e.getName());
}
}
}[/size]