English 中文(简体)
Is LINQ to XML s XElement ordered?
原标题:

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?

最佳回答

Yes, it is the same order both ways.

问题回答

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.





相关问题
Updating Linq to XML element values concatenation issues

I am trying to write a app.config / web.config error correcting app which will audit our developers applications for incorrect environment settings. I am using Linq to XML to accomplish this and I am ...

Is LINQ to XML s XElement ordered?

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

热门标签