gpt4 book ai didi

c# - 获取 Xml 属性

转载 作者:数据小太阳 更新时间:2023-10-29 02:11:22 25 4
gpt4 key购买 nike

我有一个如下所示的 Xml:

<Phrase Entry="ID">
<Ans number="1">
<Identification LastName="Bornery" Name="John" Age="23"/>
<Identification LastName="Grify" Name="Johnson" Age="29"/>
<Identification LastName="Alisen" Name="Julia" Age="38" City="NewYork" Job="Teacher"/>
<Identification LastName="Bornery" Name="John" Weight="85"/>
</Ans>
</Phrase>

我想在如下列表中列出 Xml 属性及其值:

MyList = {LastName="Bornery" , Name="John", Age="23" , LastName="Grify" , 
Name="Johnson", Age="29", LastName="Alisen",
Name="Julia", Age="38", City="NewYork", Job="Teacher",
LastName="Bornery", Name="John", Weight="85"}

最佳答案

var allAttributes = XDocument.Parse(xmlInString)
.Descendants()
.Where(e => e.HasAttributes)
.SelectMany(e => e.Attributes())
.ToList();

关于c# - 获取 Xml 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7867366/

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