Validate content of XML file?

Experiences, small talk, and other automation gossip.
atkiwi
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

<configuration>
   <appSettings>
      <Version>HB.2017.0</Version>
      <FORMAT_VERSION>2.4</FORMAT_VERSION>
      <MISC>Stuff.2014.0</MISC>
   </appSettings>
</configuration>
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();
         doc.Load(@"C:\project.exe.config");

         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.");
			     }
			 else
			 	{
			 		Report.Failure("Config", "Config is not 2017.");
				}

    }
Any help would be appreciated!

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3945
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

Hi,

I'm personally using xmldiffpatch tool to compare xml files.
https://www.nuget.org/packages/XMLDiffPatch/
https://msdn.microsoft.com/en-us/library/aa302294.aspx
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