How to compare 2 xml files using C#.net (compare only nodes..not values)

Home Page Forums BizTalk 2004 – BizTalk 2010 How to compare 2 xml files using C#.net (compare only nodes..not values)

Viewing 2 reply threads
  • Author
    Posts
    • #26206

      How to compare 2 xml files in C#.net and need to compare only nodes..not values

    • #26209

      load the file in xml doc and than

      if (doc.InnerXml.Length != doc2.InnerXml.Length)

                 {

                   return false;

                 }

    • #26226

      Xdoc1 and Xdoc2 are the XML's you want to compare and nodesnotfound gives you the list of nodes from xdoc1 not found in xdoc2.

      I just  wrote few lines quickly…test it properly.

      List<string> nodesnotFound = new List<string>();

                 bool nodefound = false;

                 foreach (XmlNode xnode1 in xdoc1)

                 {

                     foreach (XmlNode xnode2 in xdoc2)

                     {

                         if (xnode1.Name == xnode2.Name)

                             nodefound = true;

                     }

                     if (!nodefound)

                     {

                         nodesnotFound.Add(xnode1.Name);

                     }

                     nodefound = false;

                 }

Viewing 2 reply threads
  • The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.