When I use LINQ to XML, is the order of the elements and attributes written out to text guaranteed to be the same order as how I added the XElement and XAttribute objects? Similarly, when I read in an XML document, is it traversed in the same order as it appears in the XML?
+1
A:
Yes, you can use indexing as well, which maps directly to the order they appear in the document.
goldenratio
2009-11-13 17:44:32
+1
A:
However, be aware that XML attributes are specified to be unordered; it would be unwise to rely on any particular ordering of attributes in any code. As a practical matter, many API's don't even make it discoverable in which order the attributes were
Sibling elements have order; attributes do not.
Eamon Nerbonne
2009-11-13 18:40:57