Search in sources :

Example 1 with JDOMXPath

use of org.jaxen.jdom.JDOMXPath in project Asqatasun by Asqatasun.

the class KbCsvMojo method getUrls.

private List<String> getUrls(String url) throws JDOMException, JaxenException, IOException {
    SAXBuilder builder = new SAXBuilder();
    EntityResolver resolver = new XhtmlEntityResolver();
    builder.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
    builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    builder.setEntityResolver(resolver);
    Document document = builder.build(new URL(url));
    XPath xpath = new JDOMXPath("//*[@id='resultat']//*[@href]/@href");
    List<Attribute> results = xpath.selectNodes(document);
    List<String> urls = new ArrayList<String>();
    for (Attribute attr : results) {
        urls.add(attr.getValue());
    }
    return urls;
}
Also used : XPath(org.jaxen.XPath) JDOMXPath(org.jaxen.jdom.JDOMXPath) SAXBuilder(org.jdom.input.SAXBuilder) JDOMXPath(org.jaxen.jdom.JDOMXPath) Attribute(org.jdom.Attribute) ArrayList(java.util.ArrayList) EntityResolver(org.xml.sax.EntityResolver) Document(org.jdom.Document) URL(java.net.URL)

Aggregations

URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 XPath (org.jaxen.XPath)1 JDOMXPath (org.jaxen.jdom.JDOMXPath)1 Attribute (org.jdom.Attribute)1 Document (org.jdom.Document)1 SAXBuilder (org.jdom.input.SAXBuilder)1 EntityResolver (org.xml.sax.EntityResolver)1