我有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