相关疑难解决方法(0)

例外:XPath表达式计算为意外类型System.Xml.Linq.XAttribute

我有一个像下面这样的XML文件:

<Employees>
  <Employee Id="ABC001">
    <Name>Prasad 1</Name>
    <Mobile>9986730630</Mobile>
    <Address Type="Perminant">
      <City>City1</City>
      <Country>India</Country>
    </Address>
    <Address Type="Temporary">
      <City>City2</City>
      <Country>India</Country>
    </Address>
  </Employee>
Run Code Online (Sandbox Code Playgroud)

现在我想要获取所有地址类型.

我尝试下面使用XPath,我得到例外.

var xPathString = @"//Employee/Address/@Type";
doc.XPathSelectElements(xPathString); // doc is XDocument.Load("xml file Path")
Run Code Online (Sandbox Code Playgroud)

例外:XPath表达式计算为意外类型System.Xml.Linq.XAttribute.

我的XPath有什么问题吗?

c# xml xpath linq-to-xml

6
推荐指数
1
解决办法
1530
查看次数

标签 统计

c# ×1

linq-to-xml ×1

xml ×1

xpath ×1