Is there an easy way to compare if 2 XDocuments are equal ignoring element/attribute order?

后端 未结 3 1956
栀梦
栀梦 2021-01-03 22:33

Unit testing my serialization code I found one failed because I had attributes listed in a different order (I\'m just comparing the XDocument.ToString() values) and while I

相关标签:
3条回答
  • 2021-01-03 22:54

    Further to "Adam Ruth" I read through the microsoft link and this blog post is very useful..

    Eric White: http://blogs.msdn.com/b/ericwhite/archive/2009/01/28/equality-semantics-of-linq-to-xml-trees.aspx

    0 讨论(0)
  • 2021-01-03 22:56

    XNode has a DeepEquals function that should do the trick.

    http://msdn.microsoft.com/en-us/library/system.xml.linq.xnode.deepequals.aspx

    Update:

    It appears that the DeepEquals function doesn't always work correctly. You may be best off implementing your own comparison routine.

    http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=400469

    0 讨论(0)
  • 2021-01-03 23:07

    Try the Microsoft XML Diff and patch utility here or google "Xml Diff"

    0 讨论(0)
提交回复
热议问题