这是我使用的代码。它基于Dom4J的API,但是您可以轻松地将其转换为您喜欢的XML库的API:
public JTree build(String pathToXml) throws Exception { SAXReader reader = new SAXReader(); document doc = reader.read(pathToXml); return new JTree(build(doc.getRootElement()));}public DefaultMutableTreeNode build(Element e) { DefaultMutableTreeNode result = new DefaultMutableTreeNode(e.getText()); for(Object o : e.elements()) { Element child = (Element) o; result.add(build(child)); } return result; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)