Comparing XmlDocument for equality (content wise)

后端 未结 5 2013
情深已故
情深已故 2020-12-18 19:38

If I want to compare the contents of a XMlDocument, is it just like this?

XmlDocument doc1 = GetDoc1();
XmlDocument doc2 = GetDoc2();

if(doc1 == doc2)
{

}
         


        
5条回答
  •  心在旅途
    2020-12-18 20:27

    LBushkin is right, this is not trivial. Since XML is string data you could technically perform a hash of the contents and compare them, but that will be affected by things like whitespace.

    You could perform a structured diff (also called 'XML diffgram') between the two documents and compare the results. This is how .NET datasets keep track of changes, for example.

    Other than that you'd have to iterate through the DOM and compare elements, attributes and values to each other. If there's a schema involved then you would also have to take into account positions and so on.

提交回复
热议问题