开发者

Help with SelectSingleNode, XML and C#

I have the following SOAP response:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ABRSearchByABNResponse xmlns="http://abr.business.gov.au/ABRXMLSearch/">
<ABRPayloadSearchResults>
<request>
    <identifierSearchRequest>
        <identifierType>ABN</identifierType>
        <identifierValue>79 142 357 604</identifierValue>
    </identifierSearchRequest>
</request>
<response>
    <dateRegisterLastUpdated>2011-04-26</dateRegisterLastUpdated>
    <dateTimeRetrieved>2011-04-26T14:10:17.8169921+10:00</dateTimeRetrieved>
    <businessEntity>
        <recordLastUpdatedDate>2010-03-05</recordLastUpdatedDate>
        <ABN>
            <identifierValue>79142357604</identifierValue>
            <isCurrentIndicator>Y</isCurrentIndicator>
            <replacedIdentifierValue xsi:nil="true" />
            <replacedFrom>0001-01-01</replacedFrom>
        </ABN>
        <entityStatus>
            <effectiveTo>0001-01-01</effectiveTo>
        </entityStatus>         
        <entityType>
            <entityTypeCode>PUB</entityT开发者_JS百科ypeCode>
        </entityType>
        <mainBusinessPhysicalAddress>
            <stateCode>NSW</stateCode>
            <postcode>2000</postcode>
        </mainBusinessPhysicalAddress>
        </businessEntity>
</response>
</ABRPayloadSearchResults>
</ABRSearchByABNResponse>
</soap:Body>
</soap:Envelope>

What I am trying to get is the entityTypeCode but I have no success. I tried with

XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(searchPayload);


XmlNamespaceManager nsmgr = new XmlNamespaceManager(xDoc.NameTable);
nsmgr.AddNamespace("c", "http://abr.business.gov.au/ABRXMLSearch/");

XmlNode entityTypeCode = xDoc.SelectSingleNode("//entityTypeCode", nsmgr);

and various xpath expressions but it the xmlnode entityTypeCode is always null.

Suggestions?

Thanks in advance.


use XmlNode entityTypeCode = xDoc.SelectSingleNode("//c:entityTypeCode", nsmgr); as you have added the namespace of the element as c prefix in the namespace manager.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜