dotnet / dotnet/dotnet-api-docs

Order of attributes matter to XNode.DeepEquals

Aperta
#830 1 commento 6 reazioni 0 assegnatari Vedi su GitHub
area-System.Xml dotnet-api/prod Pri2 untriaged
Lingua principale
C#
Stelle
949
Fork
1.7k
Merge medio
3g 27m
PR unite (30g)
49

Descrizione

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.*

* ID: 5b409bae-8bca-83ad-c127-b43f5c626954
* Version Independent ID: bd83ab61-3e42-c0aa-7cd6-b5ee081ac63c
* Content: [XNode.DeepEquals(XNode, XNode) Method (System.Xml.Linq)](https://docs.microsoft.com/en-us/dotnet/api/system.xml.linq.xnode.deepequals?view=netframework-4.7.1#System_Xml_Linq_XNode_DeepEquals_System_Xml_Linq_XNode_System_Xml_Linq_XNode_)
* Content Source: [xml/System.Xml.Linq/XNode.xml](https://github.com/dotnet/dotnet-api-docs/blob/master/xml/System.Xml.Linq/XNode.xml)
* Product: **dotnet-api**
* GitHub Login: @dotnet-bot
* Microsoft Alias: **dotnetcontent**

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.