Java XPath Expression extractNodes(File xmlFile, String xpathLocator)

Here you can find the source of extractNodes(File xmlFile, String xpathLocator)

Description

extract Nodes

License

Apache License

Declaration

private static NodeList extractNodes(File xmlFile, String xpathLocator)
            throws ParserConfigurationException, SAXException, IOException, XPathExpressionException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.Document;

import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import java.io.File;
import java.io.IOException;

public class Main {
    private static NodeList extractNodes(File xmlFile, String xpathLocator)
            throws ParserConfigurationException, SAXException, IOException, XPathExpressionException {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc = builder.parse(xmlFile);
        XPathFactory xPathfactory = XPathFactory.newInstance();
        XPath xpath = xPathfactory.newXPath();
        XPathExpression expr = xpath.compile(xpathLocator);
        return (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
    }/* w  w w  .  j  av  a2s.c  om*/
}

Related

  1. dumpXpath(Node node, PrintStream printer)
  2. executePath(final Node node, final XPathExpression expression)
  3. expr(String xpathStr)
  4. extractNode(XPath xpath, String nodePath, String xmlString)
  5. extractNodeList(XPath xpath, String nodePath, String xmlString)
  6. extractValue(String xml, String xpathExpression)
  7. findElements(final String xPathExpression, final Element root)
  8. hasAnimatedPng(ImageReader reader)
  9. isLegalXPath(final String xPath)