我有XML的服务覆盖,这里的样本:读取XML通过标签名
<?xml version="1.0"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns4:loginResponse xmlns="http://www.website.com/IncTypes" xmlns:ns2="http://yyy.website.com/Security" xmlns:ns3="http://yyy.incognito.com/Service" xmlns:ns4="http:/yyy.website.com/wsdl/Security">
<ns2:errorCode>
<hasError>true</hasError>
<status>STATUS_ERROR</status>
<problemCode>-1</problemCode>
<problemMessage>Service Provider
not known</problemMessage>
<extendedInformation>Service Provider
not known</extendedInformation>
</ns2:errorCode>
</ns4:loginResponse>
</S:Body>
</S:Envelope>
我只是想获得这个标签
<hasError>true</hasError>
<status>STATUS_ERROR</status>
<problemCode>-1</problemCode>
<problemMessage>Service Provider
,这里是我的C#代码的价值:
foreach (XmlNode node in loginresp.DocumentElement)
{
if (node.FirstChild.FirstChild.HasChildNodes == true)
{
foreach (XmlNode y in node.FirstChild.FirstChild.ChildNodes)
{
HasError = y.InnerXml;
status= y.InnerXml;
}
}
}
,但它给了我要么HasError
和ErroCode
的相同的值这是<extendedInformation>Service Provider not known</extendedInformation>
我怎么能得到<hasError>true</hasError>
<status>STATUS_ERROR</status>
价值只?
哇谢谢你,工作正常,是的,我已经试过对xml.linq但一直得到错误的,我忘了提命名空间检查元素。 – Sabilv