2011-04-26 58 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前缀。