0
我有,我想分析JAVA DOM XML解析
XML大型XML文件 - XML文件有300例,其他标签 我只对案件感兴趣。我想要的是将案例标签中的所有案例和所有内容保存到只包含案例的新DOM文档中。一旦我有了这个新的DOM,我想将它发送给另一个将采用这些信息和格式的类它插入Word文档(但我会TAKLE,一旦我到达那里)
我的XML的一个例子是
<suite>
<cases>
<case>
<id/>
<title/>
<type/>
<priority/>
<estimate/>
<references/>
<custom>
<functional_area/>
<technology_dependence/>
<reviewed/>
<steps_completed>
</steps_completed>
<preconds> </preconds>
<steps_seperated>
<step>
<index/>
<content>
</content>
<expected>
</expected>
</step>
<step>
<index/>
<content>
</content>
<expected>
</expected>
</step>
<step>
</steps_seperated>
</custom>
</case>
</suite>
</cases>
有这些情形中,约400个节点
我的Java
设置初始
private void setXMLdoc(String path){
xmlDoc = getDocument(path) ;
}
获取XML文件
private Document getDocument(String path) {
try{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
DocumentBuilder builder = factory.newDocumentBuilder();
return builder.parse(path);
} catch (ParserConfigurationException ex) {
Logger.getLogger(ImportXML.class.getName()).log(Level.SEVERE, null, ex);
} catch (SAXException ex) {
Logger.getLogger(ImportXML.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(ImportXML.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
这将创建一个新的文档只包含了案件?
NodeList fList = xmlDoc.getElementsByTagName("case");
如何将打印出与案件的所有元素待办事项? /打印出所有的元素与所有的情况下待办事项提前
谢谢 - 即时通讯还很新很抱歉,如果这个问题没有意义或似乎有点基本
, – Ironluca
感谢我现在就试试。看起来不错我从来没有听说过Xpath,所以我会研究一下。 – BeginnerJavaDev