public class xmltotree { public SAXBuilder sb = null; public Document doc = null; public Element root = null; public xmltotree() throws Exception { sb = new SAXBuilder(); // 新建立构造器 doc = sb.build(new FileInputStream("company.xml")); // 读入文件 root = doc.getRootElement(); // 获得根元素element
}
public void Listelemnet(String pid, Element element) throws Exception { List find = XPath.selectNodes(root, "/ROOT/ROW[@PID=´" + pid + "´]"); int rowcount = find.size(); for (int i = 0; i < rowcount; i++) { Element findelement = (Element) find.get(i); Element element0 = new Element("ROW"); List attrib = findelement.getAttributes(); int j = attrib.size(); for (int h = 0; h < j; h++) { Attribute attribute = (Attribute) attrib.get(h); element0.setAttribute( attribute.getName(), attribute.getValue());