Java XPath Validate validateXPath(String path)

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

Description

validate X Path

License

Open Source License

Declaration

public static void validateXPath(String path) 

Method Source Code

//package com.java2s;
/*//from   w  w  w.ja va  2  s .com
 * 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 {
    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. validateXPath(final Document doc, final String xpathExpression)
  2. validateXPath(String xml, String... tests)
  3. validateXPathExpression(String xpathExpression)