日期:2014-05-20 浏览次数:20942 次
Document doc = new Document(); Element root = doc.getRootElement(); Element element111 = root.getChild("111"); List<Element> children = element111.getChildren(); for (Element element : children) { String name = element.getName();//你可以遍历取得这些子节点的名称 ... }
------解决方案--------------------
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
public class JxXml {
public JxXml(){
String xmlpath="你的文件.xml";
SAXBuilder builder=new SAXBuilder(false);
try {
Document doc=builder.build(xmlpath);
Element objExportExcel=doc.getRootElement();
Element objfields=objExportExcel.getChild("111");
List objfield=objfields.getChildren("field");
for (Iterator iter = objfield.iterator(); iter.hasNext();) {
Element field = (Element) iter.next();
String str222=field.getChildText("222");
String str333=field.getChildText("333");
}
} catch (JDOMException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new JxXml();
}
}