Java XPath Expression parseXPath(String expression, NamespaceContext nsContext)

Here you can find the source of parseXPath(String expression, NamespaceContext nsContext)

Description

parse X Path

License

Open Source License

Declaration

public static XPathExpression parseXPath(String expression, NamespaceContext nsContext)
            throws XPathExpressionException 

Method Source Code

//package com.java2s;
/*/* w ww.jav a2 s .c  o m*/
 * This file is part of experimaestro.
 * Copyright (c) 2014 B. Piwowarski <benjamin@bpiwowar.net>
 *
 * experimaestro is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * experimaestro is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with experimaestro.  If not, see <http://www.gnu.org/licenses/>.
 */

import javax.xml.namespace.NamespaceContext;

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

public class Main {
    final static private XPathFactory XPATH_FACTORY = XPathFactory.newInstance();

    public static XPathExpression parseXPath(String path) throws XPathExpressionException {
        return XPATH_FACTORY.newXPath().compile(path);
    }

    public static XPathExpression parseXPath(String expression, NamespaceContext nsContext)
            throws XPathExpressionException {
        XPath xpath = XPATH_FACTORY.newXPath();
        xpath.setNamespaceContext(nsContext);
        return xpath.compile(expression);
    }
}

Related

  1. loadFromXmlNode(String xmlFile, String prefix)
  2. loadNodeList(String file, String path)
  3. merge(XPathExpression expression, InputStream... files)
  4. modelPathExpr()
  5. parseXMLValue(String xml, String xpathExpression)
  6. pathExists(XPath xpath, String expression, Object object)
  7. readXmlNodeChildFromFile(String xPath, String path, NamespaceContext nsContext)
  8. replaceXPathNode(Node replaceThis, Node replaceWith)
  9. singleXPathNode(String expression, Node node)