Order of attributes matter to XNode.DeepEquals #830
Labels
area-System.Xml
dotnet-api/prod
Pri2
Indicates issues/PRs that are medium priority
untriaged
New issue has not been triaged by the area owner
The description is misleading: "Two XElement nodes are equal if they have the same tag name, the same set of attributes with the same values" would suggest that order of attributes doesn't matter (since it is a set), but the order does matter.
E.g. following will result in false, i.e. noequivalent XMLs.
XElement xmlTree1 = new XElement("Root",
new XAttribute("Att1", 1),
new XAttribute("Att2", 2)
);
XElement xmlTree2 = new XElement("Root",
new XAttribute("Att2", 2),
new XAttribute("Att1", 1)
);
Console.WriteLine(XNode.DeepEquals(xmlTree1, xmlTree2));
I am not sure how exactly are the attributes compared, but perhaps "two equal length sequences of equal attributes" is closer to truth.
EDIT:
The reference source says that my description of attribute equality is basically accurate, attributes are compared from first to last on both sides and each one must have same name and value:
https://referencesource.microsoft.com/#System.Xml.Linq/System/Xml/Linq/XLinq.cs,d4ee71a752e8b485
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: