【发布时间】:2016-02-17 13:56:08
【问题描述】:
我有这样的 XML 格式
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<abresponse IssuerId="5" ReturnCode="Success" Version="12.2">
<XMLAuthenticateResponse>
<ACL>
<ACL Name="PM.ADMIN" Value="1" />
<ACL Name="PM.APPROVE" Value="1" />
<ACL Name="PM.LOGIN" Value="1" />
<ACL Name="PM.SUPPORT" Value="1" />
</ACL>
<User EMailAddress="abc@xyz.com" GroupName="Program Administrator" UserId="2095965" Username="test" />
</XMLAuthenticateResponse>
</abresponse >
如何从 XML 中获取 ReturnCode..
我将其作为 API 响应获取,因此我已对其进行了转换
XElement response = XElement.Parse(xDoc.OuterXml)
string retcode=response.Descendants("OrbiscomResponse")
.Attributes("ReturnCode")
.FirstOrDefault()
.Value
.Tostring();
【问题讨论】:
-
发布您当前的代码并解释您遇到的问题,以便我们帮助解决它。
-
向我们展示你的努力
-
可以将xml加载为
string,找到ReturnCode=并获取值。理论上。 -
试试
XmlElement.GetAttribute Method -
您的 XML 有
abresponse但您的代码正在寻找OrbiscomResponse还有什么是xDoc?您不需要解析 xml 两次。