嵌套命名空间:如何检索内部节点

I have this scenario, returned by a SOAP WS

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
        <ns1:myFunctionEnvelopeName xsi:type="xsd:string" xmlns:ns1="http://fooNameSpace.comm">
            <myFunctionName xmlns="http://barNameSpace.com">
                [some nodes here]
            </myFunctionName>
        </ns1:myFunctionEnvelopeName>
    </soapenv:Body>
</soapenv:Envelope>

I want to select subnodes child of myFunctionName but I have some issues

  • If i register ns1 namespace into my XPath I'm able only to select myFunctionEnevelopeName (even if I try with getElementsByTagName() I receive back 0 nodes
  • If I register, let's say, ns2 with barNameSpace.com, my query will not return my elements
    • If I don't register any namespace my query will not return my elements

Only workaround I have found is to

  • Register ns1 as namespace of XPath
  • Retrieve "main node" (myFunctionEnevelopeName)
  • Extract textContent from "main node" (that of course is a valid xml)
  • Create a brand-new Xpath with the text content obtained
  • Register ns2 as namespace of brand-new Xpath
  • Obtain what I want

I'm sure that exists a clever method to do that, but maybe I don't know it. Someone could give me pointers?

XPath itself doesn't prevent you from registering multiple namespaces and you can therefore use several prefixes in an XPath expression. For example /ns1:element-1/ns2:element-2. Using no prefix at all is the same as matching elements that don't have a namespace.

DOM API has the method getElementsByTagNameNS() for matching elements with a namespace.