I want to validate XML that it has expected node value. But I can't get node I need. Please help me)
Here is my XML. I want to get the value of this node ns3:site
<soap-env:envelope xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap-env:body>
<ns4:findsiteconfigurationbysmth xmlns:ns3="http://www.testsite.com/common" xmlns:ns2="http://www.testsite.com/plant" xmlns:ns4="someapi:com:plant" xmlns:ns5="someapi:com:reasoncode">
<ns4:response>
<ns2:ref>SiteWD:QWERTY</ns2:ref>
<ns3:site>QWERTY</ns3:site>
<ns3:description>test description</ns3:description>
<ns3:timezone>Africa/Abidjan</ns3:timezone>
</ns4:response>
</ns4:findsiteconfigurationbysmth>
</soap-env:body>
</soap-env:envelope>
I know somehow I have to handle with namespaces. I marketed them at my code below. It didn't help me.
I've tried this approach
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document myXml = builder.parse(new File(PATH_TO_XML));
NodeList node = myXml.getDocumentElement().getElementsByTagNameNS("http://www.testsite.com/common", "ns3");
node.item(0);
At this case my result is null.
Somehow I received all text values of nodes with ns3 namespaces in one line. It was like this
SiteBO:15EBDS15EBDSAutomation testAfrica/Abidjan
But I can't reproduce the approach I used. Even though that is not what I am looking for)
Please help me to figure out where is the problem. Why I can't get the exact value of the node? What should I change?