我要xml文件说abc.xml和123.xml几乎相似,我的意思是有相同的内容,但第二个,即123.xml的内容比前一个更多.我想用Java读取这两个文件,并比较每个标记的abc.xml中的内容是否与123.xml中的内容相同,类似于对象比较.请建议我如何使用java读取xml文件并开始比较.
谢谢.
Zaz*_*Gmy 12
如果你只是想比较那么使用这个:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setCoalescing(true);
dbf.setIgnoringElementContentWhitespace(true);
dbf.setIgnoringComments(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc1 = db.parse(new File("file1.xml"));
doc1.normalizeDocument();
Document doc2 = db.parse(new File("file2.xml"));
doc2.normalizeDocument();
Assert.assertTrue(doc1.isEqualNode(doc2));
否则看到这个 http://xmlunit.sourceforge.net/
| 归档时间: | 
 | 
| 查看次数: | 19162 次 | 
| 最近记录: |