为了使用XML树的一部分创建org.w3c.dom.Document对象,我很难使用Stax解析XML。例如: child 1 child 2 child 3 =>我想为每个节点创建3个DOM对象。我尝试使用Staxmate和DomConverter进行此操作,但是我遇到了问题...我的测试项目仅取决于:stax2-api-3.0.3.jarstaxmate-2.0.0.jarjdk 1.6.0_212个测试:测试1完美运行 FileInputStream in = new FileInputStream("demo.xml"); XMLStreamReader sr = XMLInputFactory.newInstance().createXMLStreamReader(in); Document doc = new DOMConverter().buildDocument(sr); in.close();测试2抛出HIERARCHY_REQUEST_ERR异常: FileInputStream in = new FileInputStream("demo.xml"); XMLStreamReader sr = XMLInputFactory.newInstance().createXMLStreamReader(in); while (sr.hasNext()) { sr.next(); switch (sr.getEventType()) { case XMLStreamReader.START_ELEMENT: Document doc = new DOMConverter().buildDocument(sr); } } in.close(); org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted. at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.insertBefore(CoreDocumentImpl.java:391) at com.sun.org.apache.xerces.internal.dom.NodeImpl.appendChild(NodeImpl.java:235) at org.codehaus.staxmate.dom.DOMConverter._build(DOMConverter.java:292) at org.codehaus.staxmate.dom.DOMConverter.buildDocument(DOMConverter.java:171) at org.codehaus.staxmate.dom.DOMConverter.buildDocument(DOMConverter.java:152) at org.codehaus.staxmate.dom.DOMConverter.buildDocument(DOMConverter.java:131) at com.staxmatetest.Main.main(Main.java:22)请问你能帮帮我吗 ?最好的祝福,纪尧姆·勒费弗 (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 新的Staxmate版本2.0.1(可从http://wiki.fasterxml.com/StaxMateDownload获得)解决了此问题。谢谢StaxMan! (adsbygoogle = window.adsbygoogle || []).push({}); 10-06 06:03