views:

51

answers:

3

I have two XML file sitemap.xml and mouse.xml which look like below.Here the thing is that

i need to compare sitemap.xml with mouse.xml in such a way that the tag <Name></Name>.I need to compare both xml file whether the content coming inside <Name></Name> tag is same or not in c# code

Here the <Name></Name> tag are different means sitemap.xml contain "test " and mouse.xml contain "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>
+1  A: 

Try the Microsoft XML diff API.

redsquare
+1  A: 

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");
    }
adatapost
i am getting this exception Could not find file 'F:\WindowsApplication1\WindowsApplication1\bin\Debug\sitemap.xml'.
peter
Hey buddy, add physical file path for your xml files. e.g c:\xyz\sitemap.xml.
adatapost
i am a begginner,,can you tell me how to find physical path
peter
i used Server.MapPath but its showing The name 'Server' does not exist in the current context F:\WindowsApplication1\WindowsApplication1\Form
peter
Physical path mean the full path of sitemap.xml and mouse.xml.
adatapost
how to get it,,which way we can do that
peter
Yes got it,,right click on the xml file in solution explorer,From there take it path
peter
A: 

XMLUnit is awesome for xml comparison. Primarily Java based but there is a .Net port there too (I've only used the Java one): http://xmlunit.sourceforge.net/

grahamrb