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
ns1
namespace into my XPath
I'm able only to select myFunctionEnevelopeName
(even if I try with getElementsByTagName()
I receive back 0 nodesns2
with barNameSpace.com
, my query will not return my elementsOnly workaround I have found is to
ns1
as namespace of XPath
myFunctionEnevelopeName
)textContent
from "main node" (that of course is a valid xml)Xpath
with the text content obtainedns2
as namespace of brand-new Xpath
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.