1
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:A xmlns:ns2="u:a">
    <payload>
        <ns2:B xmlns:ns2="u:m:n:b>
            ....... lots of stuff......

Abbreviated all the stuff beneath it since I just need to figure out the xpath for that ns2:B

What would be the XPATH for this, right now I'm trying:

    XPath xpath = XPathFactory.newInstance().newXPath();
    XPathExpression expr1 = xpath.compile("//ns2:A/payload/ns2:B");
    nodeList = (NodeList)expr1.evaluate(doc, XPathConstants.NODESET);
    System.out.println(nodeList.getLength());
    System.out.println(nodeList);

But it's not picking up anything.

I also tried just getting the root A element with

\\ns2:A

As the xpath but that did not work either.

NolanPower
  • 409
  • 3
  • 11
  • Use `NamespaceContext` to define two namespace prefixes for the two different namespaces in play. Ignore the fact that `ns2` is used twice in your XML; choose two different namespace prefixes for the different namespaces. Namespace prefixes do not have to be the same as used in the XML; namespace URIs themselves are all that matter. See duplicate link for further details. – kjhughes Jul 21 '20 at 20:10

0 Answers0