Jump to content

How to get namespace and element name in Soap

Recommended Posts

I have a peculiar situation where I need to be able to extract the namespace and the name of the first element within the "Body" tag of a soap envelope without knowledge of the soap namespace or the name of the namespace nor the element name within the body. The soap envelope can come in many ways. For examples:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">	<S:Body>		<I_Need_This_One xmlns="king.kong.loves.godzilla">			<anythingElseDownHere>			</anythingElseDownHere>		</I_Need_This_One>	</S:Body></S:Envelope>


<Soap:Envelope xmlns:Soap="http://schemas.xmlsoap.org/soap/envelope/">	<Soap:Body>		<I_Need_This_One xmlns="king.kong.loves.godzilla">			<anythingElseDownHere>			</anythingElseDownHere>		</I_Need_This_One>	</Soap:Body></Soap:Envelope>


<Mothra:Envelope xmlns:Mothra="http://schemas.xmlsoap.org/soap/envelope/">	<Mothra:Body>		<I_Need_This_One xmlns="king.kong.loves.godzilla">			<anythingElseDownHere>			</anythingElseDownHere>		</I_Need_This_One>	</Mothra:Body></Mothra:Envelope>

And I need the XPath to extract both "I_Need_This_One" and "king.kong.loves.godzilla" into XSL variables. I've tried all kinds of variants of "/*/*[local-name()=Body]/*[local-name()]", and "//*[local-name()=Body]/*[local-name()]", but all I seem to get is everything below "anythingElseDownHere". So, I'm lost as to what to do.

Link to post
Share on other sites
  • 2 weeks later...

Try this one:<?xml version="1.0" ?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><xsl:template match="S:Body"> <xsl:variable name="firstChildName" select="child::*[1]/name()"/> <xsl:variable name="firstChildNameSpace" select="namespace-uri(child::*[1])"/> ChildName := <xsl:value-of select="$firstChildName"/> ChildNameSpace := <xsl:value-of select="$firstChildNameSpace"/></xsl:template></xsl:stylesheet>

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...