LINQ to XML 的 XElement 是有序的吗?
当我使用 LINQ to XML 时,写入文本的元素和属性的顺序是否保证与我添加 XElement 和 XAttribute 对象的顺序相同?同样,当我读取 XML 文档时,它的遍历顺序是否与 XML 中出现的顺序相同?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
但是,请注意 XML 属性被指定为无序的;在任何代码中依赖属性的任何特定顺序都是不明智的。实际上,许多 API 甚至无法发现
同级元素的属性顺序。属性没有。
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, it is the same order both ways.
是的,您也可以使用索引,它直接映射到它们在文档中出现的顺序。
Yes, you can use indexing as well, which maps directly to the order they appear in the document.