i know there are plenty of this topic in this page but sadly, i still cant get my solution..
here is my xml code:
You need to use a NamespaceContext for your XPath expression. You can read more about how to do this here
You are going to have to create a subclass of javax.xml.namespace.NamespaceContext and set it on xpath
:
xpath.setNamespaceContext(new NamespaceContext() {
@SuppressWarnings("rawtypes")
@Override
public Iterator getPrefixes(final String namespaceURI) {
return Collections.singleton("ns1").iterator();
}
@Override
public String getPrefix(final String namespaceURI) {
return "ns1";
}
@Override
public String getNamespaceURI(final String prefix) {
return "http://www.sea.com";
}
});
Then you can add the namespace prefix to the XPath expression:
XPathExpression expr = xpath.compile("//ns1:PayrollCost/*/text()");