简体   繁体   中英

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..

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM