java - How do I use XMLUnit to compare only certain parts of files? -
How do I use XMLUnit to compare 2 or more nodes (in the same name) in 2 separate files?
I have 2 XML files that look like this:
& lt; SearchResults & gt; & Lt; Result type = "header" & gt; ... Ignore it .... & lt; / Results & gt; & Lt; Result type = "seconds" & gt; ... Ignore it .... & lt; / Results & gt; & Lt; Results & gt; .... data1 .... & lt; / Results & gt; & Lt; Results & gt; .... data2 .... & lt; / Results & gt; & Lt; Results & gt; .... data3 .... & lt; / Results & gt; & Lt; Result type = "footer" & gt; ... Ignore it .... & lt; / Results & gt; & Lt; / Search results & gt;
And this is my method that I use to compare so far. The problem is that I do not want to compare parts of XML, resulting in a special flag on any type of tag. How can I do this?
Compare public with zero XMLqualityToLastTest () throws an exception {System.out.println ("checking the differences."); File first file = new file ("c: \\ eclipse \\ workspace \\ test \\ log \\" + "test_2.xml"); String file1sub = readXMLFromFile (first file); File second file = new file ("c: \\ eclipse \\ workspace \\ test \\ log \\" + "test_1.xml"); String file2sub = readXMLFromFile (second file); AssertXMLNotEqual ("Files are similar", file1sub, file2sub); AssertXMlequal ("files are not equal", file1sub, file2sub); }
I have received a vague suggestion for using Element Clififiers on page 5 of the XMLUnit Manual, but I do not understand it yet. I do not know how to tell it To compare the nodes.
Diff myDiff = new diff (file1sub, file2sub); MyDiff.overrideElementQualifier (new element name and textflexer ()); AssertXMlequal ("But they are the same when Element Qualifier control" + "which compares the test element with each element", myDiff, true);
Should I follow that path and add this class to my project?
org.apache.wink.test.diff.DiffWithAttributeQualifier
This idea put nodes in the node list and then org.custommonkey. Xmlunit.compareNodeList , but it seems that this hack is a good way to do it?
Will not XPath Test be easy to use? I imagine to do something like this
// Select all the elements, which contain no type attribute string xpath = "// no result [[not typed]]"; AssertXpathsEqual (xpath, file1sub, xpath, file1sub2)
Comments
Post a Comment