使用xpath对xml进行解析

184 阅读1分钟

参考代码

htmlClean XPath

        TagNode tagNode = new HtmlCleaner().clean(response);
        Document doc = new DomSerializer(new CleanerProperties()).createDOM(tagNode);
        XPath xPath = XPathFactory.newInstance().newXPath();
        NodeList nodeList = (NodeList) xPath.evaluate(XPATHEXP, doc, XPathConstants.NODESET);
        for (int i = 0; i < nodeList.getLength(); i++) {

            System.out.println(nodeList.item(i).getTextContent());
        }