Java XPath Expression isXPathAbsolute(String path)

Here you can find the source of isXPathAbsolute(String path)

Description

is X Path Absolute

License

Open Source License

Declaration

public static boolean isXPathAbsolute(String path) 

Method Source Code

//package com.java2s;
/*/*  www.ja  v  a 2 s .  co m*/
 * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

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

public class Main {
    private static final String REGEX_PATH_ABS = "/[^/].*";

    public static boolean isXPathAbsolute(String path) {

        validateXPath(path);

        return path.matches(REGEX_PATH_ABS);
    }

    public static void validateXPath(String path) {

        final XPath xPath = XPathFactory.newInstance().newXPath();

        try {
            xPath.compile(path);
        } catch (XPathExpressionException e) {
            throw new IllegalArgumentException("Argument is not valid XPath string", e);
        }
    }
}

Related

  1. extractValue(String xml, String xpathExpression)
  2. findElements(final String xPathExpression, final Element root)
  3. hasAnimatedPng(ImageReader reader)
  4. isLegalXPath(final String xPath)
  5. isValidFilter(String xPathString)
  6. loadFromXmlNode(String xmlFile, String prefix)
  7. loadNodeList(String file, String path)
  8. merge(XPathExpression expression, InputStream... files)
  9. modelPathExpr()