Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I compare two similar XML files in XMLUnit

Tags:

xmlunit

I want to use XMLUnit to compare two similar XML files.

Basically every thing is same, File1 is a copy of File2 , but in File2 I have changed the order of some elements in one node.

I am trying to run a test where it compares these files and returns a result of similar and not treat these files as different.

like image 939
Ahmed Avatar asked Nov 12 '09 22:11

Ahmed


People also ask

How do I compare two XML files in Visual Studio?

From the left Explorer panel, right-click the first file and choose Select for Compare from the right-click menu. Then right-click the second file and choose Compare with Selected. Both the files will be opened in the main panel, side by side in inline view mode which is comfortable for comparing the differences.

How do I compare two XML files in selenium?

To compare 2 XML files with selenium, we can use the available utilities. For example, XMLUnit can be used for comparison in Java and XMLDiffPatch with C#. If we are using Visual Studio, we need to download XMLDiffPatch NuGet package. Then write the below statements in your program to perform the simple comparison.


1 Answers

I think this link can help you - http://www.ibm.com/developerworks/java/library/j-cq121906.html#N10158

Basically, if your File1 is like -

<account>
 <id>3A-00</id>
 <name>acme</name>
</account>

And File2 is same, but only differs in order of <name> and <id> -

<account>
 <name>acme</name>
 <id>3A-00</id>
</account> 

Then you can write a test like below which will compare these and return similar.

public void testIdenticalAndSimilar() throws Exception {
   String controlXML = "<account><id>3A-00</id><name>acme</name></account>";
   String testXML = "<account><name>acme</name><id>3A-00</id></account>"; 
   Diff diff = new Diff(controlXML, testXML);
   assertTrue(diff.similar());
   assertFalse(diff.identical());
}

Hope that helps.

like image 139
Rohit Agarwal Avatar answered Nov 07 '22 04:11

Rohit Agarwal