Validate content of XML file?

Experiences, small talk, and other automation gossip.
Posts: 9
Joined: Fri May 18, 2018 5:17 pm

Validate content of XML file?

Post by atkiwi » Mon Jun 04, 2018 9:16 pm

I'm trying to write user code to validate the content of an existing XML file.

I'm automating and installation test and have to check against an XML file.

Code: Select all

I've been trying to get it to work but I keep getting a 'object reference not set to an instance of an object error'.

Code: Select all

public void ValidateConfigVersionSetting()

         XmlDocument doc = new XmlDocument();

         XmlNode = new XmlNode();
         XmlNode node = doc.DocumentElement.SelectSingleNode("/Version");

         string nodeContent = node.InnerText;

         if (nodeContent.Equals("2017.0"))
			     	Report.Success("Config", "Config is correct! 2017.");
			 		Report.Failure("Config", "Config is not 2017.");

Any help would be appreciated!

User avatar
Ranorex Guru
Ranorex Guru
Posts: 7080
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Validate content of XML file?

Post by odklizec » Tue Jun 05, 2018 7:15 am


I'm personally using xmldiffpatch tool to compare xml files.
Simply, I have a set of reference xml files (with expected results), which I'm comparing with actual xml files.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

User avatar
Posts: 3
Joined: Fri Jun 21, 2019 3:25 pm

Re: Validate content of XML file?

Post by Franz » Mon Jun 24, 2019 3:59 pm

Add an XML template file to your solution, then use an XML validator like:
Then just create a codemodule where you are validating these two files with each other.

After validating you can do something like this:

Code: Select all

foreach (var difference in Differences)
	Report.Failure("XML Validation", "Found difference: " +  difference);