How can i compare two XmlNodes regarding the content?

I will compare two XmlNodes in C# regarding the content. Let´s say i have two XmlNode´s:

            XmlDocument docA = new XmlDocument();
            docA.LoadXml("<Result name="power" value="3">");
            XmlNode nodeA = docA.SelectSingleNode("/*");
            XmlDocument docB = new XmlDocument();
            docB.LoadXml("<Result value="3" name="power">");
            XmlNode nodeB = docB.SelectSingleNode("/*");

Is there any function to compare theses nodes to get the result that they are the same (regarding content)?
The order of the attribute should have no matter.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Anurag ThakurTechnical ManagerCommented:
attribute orders in nodes does not matter - if you are comparing the attributes values and not the string value (string/outer xml will always be different if the order of attribute are different)

use the following code snippet for comparison between nodes
XmlDocument docA = new XmlDocument ();
docA.LoadXml ("<Result name=\"power\" value=\"3\">");
XmlNode nodeA = docA.SelectSingleNode ("/*");
XmlDocument docB = new XmlDocument ();
docB.LoadXml ("<Result value=\"3\" name=\"power\">");
XmlNode nodeB = docB.SelectSingleNode ("/*");
if (nodeA.Attributes.GetNamedItem("name").Value.ToString() == nodeB.Attributes.GetNamedItem("name").Value.ToString() && nodeA.Attributes.GetNamedItem("value").Value.ToString() == nodeB.Attributes.GetNamedItem("value").Value.ToString())
	Console.WriteLine("same nodes");
	Console.WriteLine("different nodes");

Open in new window

clevertrevor74Author Commented:
Thank you for answering. It´s not the exact solution i want because i do not know the names of the attributes.

In the meantime i found a solution by myself. There is the library XML diff patch. See the code snippet. You can also find the differences with this classes.
XmlDiff diff = new XmlDiff(XmlDiffOptions.IgnoreWhitespace);
XmlDocument docA = new XmlDocument();
docA.LoadXml ("<Result name=\"power\" value=\"3\">");
XmlDocument docB = new XmlDocument();
docB.LoadXml ("<Result value=\"3\" name=\"power\">");
bool isTheSameContent = diff.Compare(docA, docB); // It is the same (content) !

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.