Search in sources :

Example 6 with DOMXPath

use of org.jaxen.dom.DOMXPath in project tutorials by eugenp.

the class JaxenDemo method getAllTutorial.

public List getAllTutorial() {
    try {
        FileInputStream fileIS = new FileInputStream(this.getFile());
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = builderFactory.newDocumentBuilder();
        Document xmlDocument = builder.parse(fileIS);
        String expression = "/tutorials/tutorial";
        XPath path = new DOMXPath(expression);
        List result = path.selectNodes(xmlDocument);
        return result;
    } catch (SAXException | IOException | ParserConfigurationException | JaxenException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : DOMXPath(org.jaxen.dom.DOMXPath) XPath(org.jaxen.XPath) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DOMXPath(org.jaxen.dom.DOMXPath) IOException(java.io.IOException) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) JaxenException(org.jaxen.JaxenException) List(java.util.List) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

DOMXPath (org.jaxen.dom.DOMXPath)6 List (java.util.List)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 XPath (org.jaxen.XPath)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 JaxenException (org.jaxen.JaxenException)1 SimpleNamespaceContext (org.jaxen.SimpleNamespaceContext)1 Document (org.w3c.dom.Document)1 SAXException (org.xml.sax.SAXException)1