Here you can find the source of isXPathAbsolute(String path)
public static boolean isXPathAbsolute(String path)
//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); } } }