如何从嵌套的 xml 节点获取属性值?
我的 XElement 对象格式如下:
<Setting guid="3bcedf55-b75f-456b-b90a-a92cbbb022ga">
<PatientFieldList>
<PatientFieldSetting PatientName="UserDecision" PatentFieldLength="64" />
<PatientFieldSetting PatientName="prohibited" PatentFieldLength="128" />
</PatientFieldList>
</Setting>
我必须获取所有节点中所有属性的值,但我不知道如何:/我尝试过
xml.Elements("PatientFieldList")
xml.Descendants("PatientsSettingsFieldsList").Where(x => x.Attribute("PatentFieldLength").Value == 64)`
我有很多这样的节点,所以我想知道是否有简单的方法来访问这些节点通过“[]”或其他方式属性。
I have XElement object formated like this :
<Setting guid="3bcedf55-b75f-456b-b90a-a92cbbb022ga">
<PatientFieldList>
<PatientFieldSetting PatientName="UserDecision" PatentFieldLength="64" />
<PatientFieldSetting PatientName="prohibited" PatentFieldLength="128" />
</PatientFieldList>
</Setting>
I have to get values of all attributes in all nodes but I don't know how :/ I tried
xml.Elements("PatientFieldList")
xml.Descendants("PatientsSettingsFieldsList").Where(x => x.Attribute("PatentFieldLength").Value == 64)`
I have a lot of node like that so i wonder if there is easy way to access to these attribute by '[]' or somehow.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
代码:
输出:
Code:
Output:
这将打印出 xml 中具有属性的所有节点的属性:
如果您只希望 PatientFieldSetting 节点过滤名称:
This will print out attributes of all nodes which have attributes in your xml:
If you only want PatientFieldSetting nodes filter for the name: