如何从 LINQ to XML 中的 XElement 读取特定元素值

2023-11-27

我有一个XElement其中有这样的内容。

<Response xmlns="someurl" xmlnsLi="thew3url">
   <ErrorCode></ErrorCode>
   <Status>Success</Status>
   <Result>
       <Manufacturer>
            <ManufacturerID>46</ManufacturerID>
            <ManufacturerName>APPLE</ManufacturerName>
       </Manufacturer>
      //More Manufacturer Elements like above here
   </Result>
</Response>

我将如何读取里面的值Status元素 ?

我试过XElement stats = myXel.Descendants("Status").SingleOrDefault();但那返回的是 null。


If myXel已经是响应XElement那么它将是:

var status = myXel.Elements().Where(e => e.Name.LocalName == "Status").Single().Value;

您需要使用 LocalName 来忽略命名空间。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何从 LINQ to XML 中的 XElement 读取特定元素值 的相关文章

随机推荐