XML comparison to check if the same or different window applications are being used

I have two XML sitemap.xml and mouse.xml that looks like below. This is what it is:

I need to compare sitemap.xml with mouse.xml in such a way that the tag <Name></Name>.

I need to compare both xml files, whether the content included in the tag is <Name></Name>

the same or not in the C # code

Here the <Name></Name

> tag is different means. sitemap.xml contains "test" and mouse.xml contains "exam".

<?xml version="1.0" standalone="yes"?>
    <ObjectClass>
    <Image>00000000-0000-0000-0000-000000000000</Image>
    <Description />
    <Name>test</Name>
    <DefaultApp>00000000-0000-0000-0000-000000000000</DefaultApp>
    <ID>464930eb-e518-4d0c-b80b-184c97c7dd27</ID>
    <ParentClassID>00000000-0000-0000-0000-000000000002</ParentClassID>
    <DynamicPopulation>false</DynamicPopulation>
    <TimeoutPeriod>0</TimeoutPeriod>
    <Persist>false</Persist>
    <ClassVersion>1</ClassVersion>
    <Reinitialize>false</Reinitialize>
  </ObjectClass>

      

this is mouse.xml

 <?xml version="1.0" standalone="yes"?>
    <ObjectClass>
    <Image>00000000-0000-0000-0000-000000000000</Image>
    <Description />
    <Name>exam</Name>
    <DefaultApp>00000000-0000-0000-0000-000000000000</DefaultApp>
    <ID>464930eb-e518-4d0c-b80b-184c97c7dd27</ID>
    <ParentClassID>00000000-0000-0000-0000-000000000002</ParentClassID>
    <DynamicPopulation>false</DynamicPopulation>
    <TimeoutPeriod>0</TimeoutPeriod>
    <Persist>false</Persist>
    <ClassVersion>1</ClassVersion>
    <Reinitialize>false</Reinitialize>
  </ObjectClass>

      

+2


source to share


3 answers


Try,



 XmlDocument doc1 = new XmlDocument();
    XmlDocument doc2 = new XmlDocument();
    doc1.Load(@"c:\myproject\WindowsApplication1\sitemap.xml");
    doc2.Load(@"c:\myproject\WindowsApplication1\mouse.xml");

    XmlNodeList a = doc1.GetElementsByTagName("Name");
    XmlNodeList b = doc2.GetElementsByTagName("Name");
    if (a.Count == 1 && b.Count == 1)
    {
        if (a[0].InnerText == b[0].InnerText)
            Console.WriteLine("Equal");
        else
            Console.WriteLine("Not Equal");
    }

      

+1


source


Try Microsoft XML diff API .



+2


source


XMLUnit is great for xml comparison. Mostly in Java, but there is also a .Net port (I only used Java): http://xmlunit.sourceforge.net/

0


source







All Articles