0

Some help with this please:

   org.cyberneko.html.parsers.DOMParser dp = new DOMParser();
    dp.parse(new InputSource(new StringReader("<!DOCTYPE html><html><body><div></div></body></html>")));
    Document d = dp.getDocument();
    XPathFactory xpf = XPathFactory.newInstance();
    XPath x = xpf.newXPath();

    Node n = (Node)x.evaluate("//div",d,XPathConstants.NODE);
    System.out.println(n == null);

Any reason why n is null, thanks

4

1 回答 1

0

这是答案,如果您想访问 div 标签。

            Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File("D:\\Loic_Workspace\\Test2\\res\\test.xml"));


        System.out.println(doc.getElementsByTagName("div").item(0).getNodeName());

这给了我控制台-> div。

希望对你有帮助

于 2012-12-05T00:51:23.480 回答