olly
olly

Reputation: 23

How can I get the name of the namespace from a SOAP message?

I have a SOAP message (see below).

Using Xpath, how can I extract the name of the namespace from this message? In other words, is there an Xpath routine that will return the text "validateNewOrder"?

Any suggestions or help would be invaluable. I have been searching everywhere but not found an solution. It is driving me crazy...

Thanks!

<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
   <ns1:validateNewOrder xmlns:ns1="http://sire.rabobank.nl/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
     <sireheader xmlns="http://sire.rabobank.nl/">
       <sender>
         <compid>TEST</compid>
       </sender>
     </sireheader>
     <order xmlns="http://sire.rabobank.nl/">
       <account>123456789</account>
     </order>
   </ns1:validateNewOrder>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Upvotes: 2

Views: 2448

Answers (2)

olly
olly

Reputation: 23

I have my solution, thanks to user Obelix.

The Xpath query that I needed was

local-name(/*[local-name() = 'Envelope']/*[local-name() = 'Body']/*[1])

It does not work on the test site that I was using (apparently, the site I quoted can only process queries that return a node set), but does work in my Java code.

Now I can go out and enjoy the weekend

Olly

Upvotes: 1

AxelEckenberger
AxelEckenberger

Reputation: 16936

local-name(/*[local-name() = 'Envelope']/*[local-name() = 'Body']/*[1])

Returns the local name of the first element underneath Body in a namespace agnostic way.

Tested it with (c#)

XDocument doc = XDocument.Load(@"XMLFile1.xml");
var xpath = "local-name(/*[local-name() = 'Envelope']/*[local-name() = 'Body']/*[1])";
var res = doc.Root.XPathEvaluate(xpath);

Upvotes: 1

Related Questions