获取具有属性名称的xml节点值 [英] Get xml node value with attribute name

查看:81
本文介绍了获取具有属性名称的xml节点值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下XML。我想获取元素名称=PropertyName的值。其价值是117 Executive Drive。我怎么能得到这个?



 <   complexType  >  
< 序列 >
< element name = PropertyName type = string < span class =code-attribute> use = required value = 117 Executive Drive / >
< element 名称 = PropertyID type = 字符串 使用 = required = 2 / >
< element name = BuildingInformation >
< complexType >
< / sequence > ;
< / complexType >

解决方案

您可以使用XPath

/ complexType / sequence / element [@ value ='117 Executive Drive'] / @ name

以获得所需的结果


您可以使用 XDocument [ ^ ] + Linq查询:



 XDocument xDoc = XDocument.Load (  FullFileName.xml); 
var qry = xDoc
.Root
.Descendants( element
.Where(n => n.Attribute( value)。值== 117 Executive Drive
.Select(n = .n.Attribute( name)。 );


i have below XML. I want to get the value of element name="PropertyName". whose value is 117 Executive Drive. How i can get this?

<complexType>
<sequence>
  <element name="PropertyName" type="string" use="required" value="117 Executive Drive" />
  <element name="PropertyID" type="string" use="required" value="2" />
 <element name="BuildingInformation">
 <complexType>
 </sequence>
</complexType>

解决方案

You can use XPath

"/complexType/sequence/element[@value='117 Executive Drive']/@name"

to get the desired result


You can use XDocument[^] + Linq query:

XDocument xDoc = XDocument.Load("FullFileName.xml");
var qry = xDoc
    .Root
    .Descendants("element")
    .Where(n=>n.Attribute("value").Value=="117 Executive Drive")
    .Select(n=.n.Attribute("name").Value);


这篇关于获取具有属性名称的xml节点值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆