我有SOAP
响应,如下所示
<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">
<SOAP-ENV:Header/><SOAP-ENV:Body>
<Login xmlns=\"http://s.com/sch">
<error/>
<userid>11</userid>
</Login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我正在使用XDocument
来解析此SOAP
。我试图获得userid
我的代码是
XDocument xDocc = XDocument.Parse(responseSOAP);
string uid = xDocc.Descendants("userid").First().Value;
我无法获得11
的价值,它只返回NULL
答案 0 :(得分:2)
这应该有效:
XDocument xDocc = XDocument.Parse(responseSOAP);
XmlReader xr = xDocc.CreateReader();
xr.ReadToFollowing("userid");
string uid = xr.ReadElementString();
答案 1 :(得分:1)
试试这个:
var result = from p in xDocc.Descendants()
where p.Name.LocalName == "userid" select p.Value;