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.
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