Цикл через XML с использованием xpath
У меня есть XML, поступающий из службы WCF, я должен показать топ-10 записей searchResultsRecord из него, но я не могу пройти через него, так как Xpath ошибочен.
-<Payload xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> -<request xmlns="http://abr.business.gov.au/ABRXMLSearch/"> -<nameSearchRequest> <authenticationGUID>88bf33e2-96a6-402c-a870-47c03af2a80b</authenticationGUID> <name>ANZ</name> -<filters> -<nameType> <tradingName>N</tradingName> <legalName>N</legalName> </nameType> <postcode/> -<stateCode> <QLD>N</QLD> <NT>N</NT> <SA>N</SA> <WA>N</WA> <VIC>N</VIC> <ACT>N</ACT> <TAS>N</TAS> <NSW>N</NSW> </stateCode> </filters> </nameSearchRequest> </request> -<response xmlns="http://abr.business.gov.au/ABRXMLSearch/"> <usageStatement>The Registrar of the ABR monitors the quality of the information available on this website and updates the information regularly. However, neither the Registrar of the ABR nor the Commonwealth guarantee that the information available through this service (including search results) is accurate, up to date, complete or accept any liability arising from the use of or reliance upon this site.</usageStatement> <dateRegisterLastUpdated>2019-10-23</dateRegisterLastUpdated> <dateTimeRetrieved>2019-10-23T12:48:10.9298689+05:30</dateTimeRetrieved> -<searchResultsList> <numberOfRecords>201</numberOfRecords> <exceedsMaximum>N</exceedsMaximum> -<searchResultsRecord> -<ABN> <identifierValue>11005357522</identifierValue> <identifierStatus>Active</identifierStatus> </ABN> -<businessName> <organisationName>ANZ</organisationName> <score>100</score> <isCurrentIndicator>Y</isCurrentIndicator> </businessName> -<mainBusinessPhysicalAddress> <stateCode>VIC</stateCode> <postcode>3008</postcode> <isCurrentIndicator>Y</isCurrentIndicator> </mainBusinessPhysicalAddress> </searchResultsRecord> -<searchResultsRecord> -<ABN> <identifierValue>30146899103</identifierValue> <identifierStatus>Cancelled</identifierStatus> </ABN> -<mainName> <organisationName>ANZ COMPANIES PTY LIMITED</organisationName> <score>100</score> <isCurrentIndicator>Y</isCurrentIndicator> </mainName> -<mainBusinessPhysicalAddress> <stateCode>NSW</stateCode> <postcode>2134</postcode> <isCurrentIndicator>Y</isCurrentIndicator> </mainBusinessPhysicalAddress> </searchResultsRecord> -<searchResultsRecord> -<ABN> <identifierValue>22169448220</identifierValue> <identifierStatus>Active</identifierStatus> </ABN> -<mainName> <organisationName>ANZ CORPORATION PTY LTD</organisationName> <score>100</score> <isCurrentIndicator>Y</isCurrentIndicator> </mainName> -<mainBusinessPhysicalAddress> <stateCode>NSW</stateCode> <postcode>2009</postcode> <isCurrentIndicator>Y</isCurrentIndicator> </mainBusinessPhysicalAddress> </searchResultsRecord> -<searchResultsRecord> -<ABN> <identifierValue>32601478849</identifierValue> <identifierStatus>Active</identifierStatus> </ABN> -<businessName> <organisationName>AUS AND NZ</organisationName> <score>100</score> <isCurrentIndicator>Y</isCurrentIndicator> </businessName> -<mainBusinessPhysicalAddress> <stateCode>NSW</stateCode> <postcode>2135</postcode> <isCurrentIndicator>Y</isCurrentIndicator> </mainBusinessPhysicalAddress> </searchResultsRecord> -<searchResultsRecord> -<ABN> <identifierValue>62143244035</identifierValue> <identifierStatus>Cancelled</identifierStatus> </ABN> -<mainName> <organisationName>AUS-NZ Pty Ltd</organisationName> <score>100</score> <isCurrentIndicator>Y</isCurrentIndicator> </mainName> -<mainBusinessPhysicalAddress> <stateCode>QLD</stateCode> <postcode>4818</postcode> <isCurrentIndicator>Y</isCurrentIndicator> </mainBusinessPhysicalAddress> </searchResultsRecord> -<searchResultsRecord> -<ABN> <identifierValue>58620076075</identifierValue> <identifierStatus>Active</identifierStatus> </ABN> -<mainName> <organisationName>AAIH ANZ PTY LTD</organisationName> <score>97</score> <isCurrentIndicator>Y</isCurrentIndicator> </mainName> -<mainBusinessPhysicalAddress> <stateCode>QLD</stateCode> <postcode>4006</postcode> <isCurrentIndicator>Y</isCurrentIndicator> </mainBusinessPhysicalAddress> </searchResultsRecord> -<searchResultsRecord> -<ABN> <identifierValue>71884645219</identifierValue> <identifierStatus>Active</identifierStatus> </ABN> -<legalName> <fullName>ABAS ANZ</fullName> <score>97</score> <isCurrentIndicator>N</isCurrentIndicator> </legalName> -<mainBusinessPhysicalAddress> <stateCode>NSW</stateCode> <postcode>2197</postcode> <isCurrentIndicator>Y</isCurrentIndicator> </mainBusinessPhysicalAddress> </searchResultsRecord> -<searchResultsRecord> -<ABN> <identifierValue>30124078119</identifierValue> <identifierStatus>Cancelled</identifierStatus> </ABN> -<mainName> <organisationName>ABC (AUST & NZ) PTY LTD</organisationName> <score>97</score> <isCurrentIndicator>Y</isCurrentIndicator> </mainName> -<mainBusinessPhysicalAddress> <stateCode>VIC</stateCode> <postcode>3181</postcode> <isCurrentIndicator>Y</isCurrentIndicator> </mainBusinessPhysicalAddress> </searchResultsRecord> -<searchResultsRecord> -<ABN> <identifierValue>53863463962</identifierValue> <identifierStatus>Cancelled</identifierStatus> </ABN> -<businessName> <organisationName>ABIM ANZ</organisationName> <score>97</score> <isCurrentIndicator>N</isCurrentIndicator> </businessName> -<mainBusinessPhysicalAddress> <stateCode>VIC</stateCode> <postcode>3066</postcode> <isCurrentIndicator>Y</isCurrentIndicator> </mainBusinessPhysicalAddress> </searchResultsRecord> -<searchResultsRecord> -<ABN> <identifierValue>82133580015</identifierValue> <identifierStatus>Active</identifierStatus> </ABN> -<mainName> <organisationName>ACCA Australia & New Zealand Ltd</organisationName> <score>97</score> <isCurrentIndicator>Y</isCurrentIndicator> </mainName> -<mainBusinessPhysicalAddress> <stateCode>NSW</stateCode> <postcode>2000</postcode> <isCurrentIndicator>Y</isCurrentIndicator> </mainBusinessPhysicalAddress> </searchResultsRecord> -<searchResultsRecord> -<ABN> <identifierValue>84612765143</identifierValue> <identifierStatus>Active</identifierStatus> </ABN> -<mainName> <organisationName>ACCELEDENT AUSTRALIA NZ PTY LTD</organisationName> <score>97</score> <isCurrentIndicator>Y</isCurrentIndicator> </mainName> -<mainBusinessPhysicalAddress> <stateCode>QLD</stateCode> <postcode>4165</postcode> <isCurrentIndicator>Y</isCurrentIndicator> </mainBusinessPhysicalAddress> </searchResultsRecord> -<searchResultsRecord> -<ABN> <identifierValue>89000563002</identifierValue> <identifierStatus>Cancelled</identifierStatus> </ABN> -<mainTradingName> <organisationName>ACHESON ANZ PTY LTD</organisationName> <score>97</score> <isCurrentIndicator>Y</isCurrentIndicator> </mainTradingName> -<mainBusinessPhysicalAddress> <stateCode>NSW</stateCode> <postcode>2170</postcode> <isCurrentIndicator>Y</isCurrentIndicator> </mainBusinessPhysicalAddress> </searchResultsRecord> -<ABN> <identifierValue>51621646277</identifierValue> <identifierStatus>Active</identifierStatus> </ABN> -<mainName> <organisationName>AIRLINES FOR AUSTRALIA AND NEW ZEALAND LTD</organisationName> <score>97</score> <isCurrentIndicator>Y</isCurrentIndicator> </mainName> -<mainBusinessPhysicalAddress> <stateCode>NSW</stateCode> <postcode>2020</postcode> <isCurrentIndicator>Y</isCurrentIndicator> </mainBusinessPhysicalAddress> </searchResultsRecord>
Что я уже пробовал:
foreach (XElement xe in doc.Descendants("searchResultsRecord").Take(50)) { XmlDocument doc1 = new XmlDocument(); xe.Add(doc1); }
ОПЕРАЦИОННАЯ
foreach (XmlNode result in responseXml.SelectNodes("//Payload/searchResultsList/searchResultsRecord")) { XmlDocument doc1 = new XmlDocument(); result.AppendChild(doc1); }