XPath: get element from node with namespace?

I have a problem retrieving an element value via XPath. The XML is like

<?xml version="1.0" encoding="UTF-8"?>

<SOAP:Envelope ...>

<SOAP:Header>

...

</SOAP:Header>

<SOAP:Body>

<A xmlns="myns/">

<B>

<C>

<D>123</D>

...

I want to retrieve node 'D'. I was able to select node 'A' with this XPath:

//SOAP:Body/child::*[namespace-uri()='myns']

but can't get further. E.g.

//SOAP:Body/child::*[namespace-uri()='myns']/B

doesn't work ...?

[740 byte] By [MartinHilperta] at [2007-10-2 5:45:20]
# 1

How about?

<xsl:for-each select = "//SOAP:body">

<xsl:value-of select="." />

<xsl:if test="(position() = last())">

<xsl:value-of select="." />

</xsl:if>

</xsl:for-each>

Boeing-737a at 2007-7-16 1:55:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

No, it doesn't work because you don't have a "B" element, you have a "B in the default namespace" element. Do a Google search for "xpath default namespace" and you will see the problems other people have had with this design flaw in XPath.

Apparently XPath 2.0 has a fix for the problem.

DrClapa at 2007-7-16 1:55:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
My 'solution' is://SOAP:Body/child::*[namespace-uri()='myns']/*/*/*It works, but I don't like it as I'm used to read a '*' as a wildcard that can result in multiple hits. :-/
MartinHilperta at 2007-7-16 1:55:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
Alas, this doesn't work if i want to select a subnode that has an additional namespace attribute, e.g.<C mns:IsValid='true>I tried to state this namespace-uri property everywhere but I don't get the nodes with these XPaths.>
MartinHilperta at 2007-7-16 1:55:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

> I have a problem retrieving an element value via

> XPath. The XML is like

>

> > <?xml version="1.0" encoding="UTF-8"?>

> <SOAP:Envelope ...>

><SOAP:Header>

> ...

></SOAP:Header>

> <SOAP:Body>

> <A xmlns="myns/">

><B>

> <C>

> <D>123</D>

> ode]

>

> I want to retrieve node 'D'. I was able to select

> node 'A' with this XPath:

>

> [code]

> //SOAP:Body/child::*[namespace-uri()='myns']

>

>

> but can't get further. E.g.

>

> > //SOAP:Body/child::*[namespace-uri()='myns']/B

>

>

> doesn't work ...?

Is there any solution to this problem?

MartinHilperta at 2007-7-16 1:55:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6
No, it doesn't work because you don't have a "B" element, you have a "B in the default namespace" element.As I already said, if you scan back to November.I believe that the XPath function "local-name()" might help here.
DrClapa at 2007-7-16 1:55:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...