How can I compare 2 XML files

Hi,

I am implementing regression testing for a process which output is an XML file.

what is the best option for comparing the content of 2 XML file (one pre-defined to be used for this regression, and the new one generated during the test case execution) with Katalon?

1 Like

You can either do a char-by-char comparison of two strings, or test the files/strings for (essentially) XML semantic equivalence. See the top answer in this SO post:

1 Like

Hi,
Could you please give more details on the settings to use XMLUnit in Katalon.
Is there a Package or a Class to import?
In setting I added xmlunit-core-2.8.2-tests.jar and xmlunit-core-2.8.2.jar, but still error on groovy.lang.MissingPropertyException: No such property: XMLUnit
Thanks

1 Like

you can try converting your xml to json file and use json parser to compare 2 files and internal nodes.

Have a look at my post:

My solution applies to any text file. It compares line-by-line basis. It can compare any format: JSON, YAML, CSV, *.js, not only XML, It assumes that 2 files are “pretty-printed” before comparison.

Hi,
Can you please tell me what jar file do I need to download or if I need import anything or set any settings to compile this code?

Thanks

XMLUnit.setIgnoreWhitespace(true)
XMLUnit.setIgnoreComments(true)
XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true)
XMLUnit.setNormalizeWhitespace(true)

XMLUnit.compareXML(expectedXml, actualXml)