Reputation: 3
XPATH : //requestHeader//*[local-name()='clientUsername']
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:req="http://www.ABC.com/ws/requestHeader"
xmlns:web="http://com/ABC/XXX/YYY">
<soapenv:Header/>
<soapenv:Body>
<web:isServiceUp>
<web:requestHeader>
<req:clientUsername>GENT</req:clientUsername>
<req:languageCode>?</req:languageCode>
</web:requestHeader>
</web:isServiceUp>
</soapenv:Body>
</soapenv:Envelope>
It suppose to be return GENT but It returns empty string...
Upvotes: 0
Views: 52
Reputation: 122364
The requestHeader
element is in the http://com/ABC/XXX/YYY
namespace, so //requestHeader
will not find it (that XPath is looking for an element named requestHeader
in no namespace). You either need to do the same local-name()
trick you're doing with clientUsername
or set up the appropriate prefix binding using whatever mechanism your XPath library provides, and then use that prefix in the expression.
You've tagged your question "java" so if you're using javax.xml.xpath
you need to look up the setNamespaceContext
method on XPath
.
Upvotes: 1
Reputation: 95488
You need to have the following:
//web:requestHeader//*[local-name()='clientUsername']
You need to look for web:requestHeader
and not just requestHeader
:
You can test this out here. Try it with just requestHeader
and you'll see that it returns nothing. When you change it to web:requestHeader
, you will get the element that you're looking for.
Upvotes: 2