0

I have the following soap response and want to extract the list of products:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <listProductsResponse xmlns="http://warehouse.acme.com/ws">
         <listProductsResult>
            <listProductsResult>
               <productName>hammer</productName>
               <productId>54112</productId>
            </listProductsResult>
            <listProductsResult>
               <productName>drill</productName>
               <productId>54113</productId>
            </listProductsResult>
            <listProductsResult>
               <productName>circular saw</productName>
               <productId>54114</productId>
            </listProductsResult>
            <listProductsResult>
               <productName>jigsaw</productName>
               <productId>54115</productId>
            </listProductsResult>
         </listProductsResult>
      </listProductsResponse>
   </soapenv:Body>
</soapenv:Envelope>

The following XPath returns a "No Match". I'm wondering why?

/soapenv:Envelope/soapenv:Body/ns:listProductsResponse

The following is working but seems to me a dirty approach since a namespace is specified for listProductsResponse:

/soapenv:Envelope/soapenv:Body/*[local-name()="listProductsResponse"]
Christian68
  • 845
  • 4
  • 13
  • 24
  • Which xpath engine you are using, you need to tell that to be aware of the namespace. – SomeDude Sep 25 '17 at 14:15
  • Possible duplicate of [How does XPath deal with XML namespaces?](https://stackoverflow.com/questions/40796231/how-does-xpath-deal-with-xml-namespaces) – kjhughes Sep 25 '17 at 14:18
  • @svasa Thanks - I was testing with https://codebeautify.org/Xpath-Tester first. – Christian68 Sep 25 '17 at 16:00

0 Answers0