簡體   English   中英

有關SelectSingleNode,XML和C#的幫助

[英]Help with SelectSingleNode, XML and C#

我有以下SOAP響應:

<?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</entityTypeCode>
        </entityType>
        <mainBusinessPhysicalAddress>
            <stateCode>NSW</stateCode>
            <postcode>2000</postcode>
        </mainBusinessPhysicalAddress>
        </businessEntity>
</response>
</ABRPayloadSearchResults>
</ABRSearchByABNResponse>
</soap:Body>
</soap:Envelope>

我想要得到的是entityTypeCode,但是我沒有成功。 我嘗試過

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);

以及各種xpath表達式,但xmlnodeEntityTypeCode始終為null。

有什么建議嗎?

提前致謝。

使用XmlNode entityTypeCode = xDoc.SelectSingleNode("//c:entityTypeCode", nsmgr); 因為您已經在名稱空間管理器中將元素的名稱空間添加為c前綴。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM