kawadw
kawadw

Reputation: 45

xml file compare

how to simply compare two xml files from element name. if any element name is not matched it should return true, else false.. I am using

 var matches = from a in file1.Element("in_mind").Descendants()
                          join b in file2.Element("in_mind").Descendants() on a.Name equals b.Name
                          select new { First = a, Second = b };

            foreach (var n in matches)
                if(n.First.ToString().Intersect(n.Second.ToString()).Count()>0)
                {

                }
                else
                {
                    MessageBox.Show("not matched");
                    return;
                }

but it is not checking the element name..

Upvotes: 0

Views: 331

Answers (1)

Athina
Athina

Reputation: 533

Maybe something like this? Get all descendant's names from both files and check if they are the same. I don't know if it is what you wanted to do.

var elements1=(from e in file1.Element("in_mind").Descendants() select e.Name).ToList();
var elements2=(from e in file2.Element("in_mind").Descendants() select e.Name).ToList();

for(int i=0;i<elements1.Count;i++)
{
    if(elements1[i]!=elements2[i])
    {
        return false;
    }
}

return true;

Upvotes: 1

Related Questions