A
A
aydinka2015-12-19 19:42:26
XPath
aydinka, 2015-12-19 19:42:26

Getting values ​​in XML via XPath, I can't because of namespace. How to be?

Hi all!
I have the following XML that I receive from a web service

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
     <getProductDetailsResponse xmlns="http://warehouse.example.com/ws">
       <getProductDetailsResult>
         <productID>12345</productID>
         <productName>Стакан граненый</productName>
         <description>Стакан граненый. 250 мл.</description>
         <price>9.95</price>
         <currency>
             <code>840</code>
             <alpha3>USD</alpha3>
             <sign>$</sign>
             <name>US dollar</name>
             <accuracy>2</accuracy>
         </currency>
         <inStock>true</inStock>
       </getProductDetailsResult>
     </getProductDetailsResponse>
   </soap:Body>
</soap:Envelope>

If I remove the namespace - xmlns=" warehouse.example.com/ws " , then I can get all the values. For example, the value of the price
XPath tag is -
/soap:Envelope/soap:Body/getProductDetailsResponse/getProductDetailsResult/price/text()

But I can’t do it with namespace, what should I do?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
wellusion, 2015-12-22
@wellusion

Use local-name()
Like this: //*[local-name()='price']

A
aydinka, 2015-12-19
@aydinka

Already found the answer to my question
Don't use namespaces in aged XML or eat them

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question