My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Featured
Downloads
Wiki pages
Links

A quick XPath analyser with a SAX Parser. Some syntaxes are invalide, but all using syntax are presents. It's possible to catch many XPath in the same time.

XPathXMLHandler handler=new XPathXMLHandler()
  {
    @Override
    public void findXPathNode(SAXXPath xpath, Object node)
    {
      System.out.println("node="+node);
    }
  };
handler.setXPaths(XPathXMLHandler.toXPaths("//b[@at_a='s3']/c"));
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
parser.parse(new InputSource(new StringReader(xml)), handler);

The node is orphan, with attributs and all child texts nodes.

It's possible to use with HtmlParser.

XPathXMLHandler handler=new XPathXMLHandler()
{
  @Override
  public void findXpathNode(SAXXPath xpath, Object node)
  {
    System.out.println("node="+node);
  }
};
handler.setXPaths(XPathXMLHandler.toXPaths("//body/h1"));
HtmlParser htmlParser = new HtmlParser(XmlViolationPolicy.ALLOW);
htmlParser.setDoctypeExpectation(DoctypeExpectation.NO_DOCTYPE_ERRORS);
htmlParser.setContentHandler(handler);
htmlParser.parse(new InputSource(new StringReader(html)));

Accepted syntax

Powered by Google Project Hosting