How To Compare Two XML Files in Selenium?

Timothy Joseph | February 21, 2022

How To 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#.

Below is a sample program to perform XML comparison in C#:

  1. If we are using Visual Studio, we need to download XMLDiffPatch NuGet package.
  2. Then write the below statements in your program to perform the simple comparison.

    XmlDiff xmlcompare = new XmlDiff();
    bool bIdentical = xmldiff.Compare(expectedxml, actualxml);

  3. Here bIdentical will return true if data matches and false if there is any mismatch.
  4. XML files can also be read from a local system using XMLReader.
  5. Similarly, there are other capabilities of this package that can be used to perform XML handling if needed.

Need reliable QA resources to ramp up your existing processes?

Disclaimer

This publication is for informational purposes only, and nothing contained in it should be considered legal advice. We expressly disclaim any warranty or responsibility for damages arising out of this information and encourage you to consult with legal counsel regarding your specific needs. We do not undertake any duty to update previously posted materials.

Post a Comment