Java XPath Create getXPath(String expression)

Here you can find the source of getXPath(String expression)

Description

get X Path

License

Open Source License

Declaration

public static XPathExpression getXPath(String expression) 

Method Source Code

//package com.java2s;

import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

public class Main {
    private static XPathFactory xpathFactory;

    public static XPathExpression getXPath(String expression) {
        try {/*from  w  ww  .  j  av  a 2s. c o  m*/
            return getXPathFactory().newXPath().compile(expression);
        } catch (XPathExpressionException e) {
            throw new RuntimeException("Invalid XPath Expression " + expression, e);
        }
    }

    /**
     * Gets the XPath factory, creating it if necessary.
     * 
     * @return the XPath factory.
     */
    public static synchronized XPathFactory getXPathFactory() {
        if (xpathFactory == null) {
            xpathFactory = XPathFactory.newInstance();
        }
        return xpathFactory;
    }
}

Related

  1. getXPath(Node node)
  2. getXPath(Node node)
  3. getXPath(Node node)
  4. getXPath(Node node, String xpath)
  5. getXPath(String exp, NamespaceContext ctx)
  6. getXPathExpression(final Node node)
  7. getXPathExpression(String expression)
  8. getXPathExpression(String path)
  9. getXPathExpression(String xpath, NamespaceContext namespaceContext)