Question

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?

Was it helpful?

Solution

Yes, it is the same order both ways.

OTHER TIPS

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.

Yes, you can use indexing as well, which maps directly to the order they appear in the document.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top