gpt4 book ai didi

c# - 如何按属性对 XDocument 进行排序?

转载 作者:可可西里 更新时间:2023-11-01 08:24:16 25 4
gpt4 key购买 nike

我有一些 XML

<Users>
<User Name="Z"/>
<User Name="D"/>
<User Name="A"/>
</User>

我想按姓名 排序。我使用 XDocument 加载该 xml。如何查看按名称排序的 xml?

最佳答案

如果 XmlDocument 不是这种情况,您可以使用 LINQ to Xml 进行排序

XDocument input = XDocument.Load(@"input.xml");
XDocument output = new XDocument(
new XElement("Users",
from node in input.Root.Elements()
orderby node.Attribute("Name").Value descending
select node));

关于c# - 如何按属性对 XDocument 进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2232089/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com