2011-04-26 75 views
0

我有以下的SOAP響應:幫助的SelectSingleNode,XML和C#

<?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表達式,但它的xmlnode entityTypeCode始終爲空。

對此提出建議?

在此先感謝。

回答

3

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