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