Using XNode.DeepEquals()
to compare xml elements, it unexpectedly returns false
on two xml documents that I think should be equivalent.
Example
var xmlFromString = XDocument.Parse("<someXml xmlns=\"someNamespace\"/>");
var xmlDirect = new XDocument(new XElement(
XNamespace.Get("someNamespace") + "someXml"));
Console.WriteLine(xmlFromString.ToString());
Console.WriteLine(xmlDirect.ToString());
Console.WriteLine(XNode.DeepEquals(xmlFromString, xmlDirect));
Console.WriteLine(xmlFromString.ToString() == xmlDirect.ToString());
Output
<someXml xmlns="someNamespace" />
<someXml xmlns="someNamespace" />
False
True
The strings are considered equal, but the XML trees are not. Why?
DeepEquals
reports false just for the root element, too... so it's not a document declaration issue, for example. – Weekend