Get XML node with namespace in java

前端 未结 3 1510
失恋的感觉
失恋的感觉 2021-01-21 15:43

I have the next XML:




        
3条回答
  •  無奈伤痛
    2021-01-21 16:10

    You can try to work with xpath

    public static NodeList getNodesWithXPath(Node aNode, String aXPath) {
        try {
            XPathFactory xPathfactory = XPathFactory.newInstance();
            XPath xpath = xPathfactory.newXPath();
            XPathExpression xPathExpression = xpath.compile(aXPath);
            return (NodeList) xPathExpression.evaluate(aNode, XPathConstants.NODESET);
        } catch (XPathExpressionException e) {
            // ignore
        } catch (NullPointerException e) {
            // ignore
        }
        return null;
    }
    

提交回复
热议问题