gtx911
gtx911

Reputation: 1289

Xpath3 - Get name from SOAP message

This is my SOAP message and I want to get the name of the child element of soap:Body:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope/" xmlns:pref="URI_SOAP_WS">
   <soap:Body>
      <pref:book>
         <pref:author>Gambardella, Matthew</pref:author>
         <pref:title>XML Developer's Guide</pref:title>
         <pref:genre>Computer</pref:genre>
         <pref:price>44.95</pref:price>
         <pref:publish_date>2000-10-01</pref:publish_date>
         <pref:description>An in-depth look XML</pref:description>
      </pref:book>
   </soap:Body>
</soap:Envelope>

How can I get the name of <pref:book>?

I want to use for comparison in a switch.

Upvotes: 1

Views: 168

Answers (1)

har07
har07

Reputation: 89285

Assuming that you want to get element name of direct child of <soap:Body>, so in this case it means a string "pref:book", you can try this way :

declare namespace soap = "http://www.w3.org/2003/05/soap-envelope/";
/soap:Envelope/soap:Body/*/name()

Output will be pref:book, exactly as needed. Tested using XPath 2.0 here : http://videlibri.sourceforge.net/cgi-bin/xidelcgi

Upvotes: 2

Related Questions