> Is there a way of validating and XPath? In this case , I am
> accepting an XPath from the user and I need to validate the XPath
> syntax. Is there a regular expression available that anyone can
> direct me to, to validate a XPath?
The W3C has an applet that checks the grammar of an XPath expression:
<URL:http://www.w3.org/2002/11/xquery-xpath-applets/xpathApplet.html>.
I think however that applet is for XPath 2.0 while the Microsoft .NET
framework application currently support XPath 1.0 only. You might want
to check the W3C web site whether an applet checking XPath 1.0 is
available too.

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Phil Fearon - 08 Feb 2008 07:57 GMT
Yes, there is a way of validating the syntax of an XPath expression in .NET,
though it will not pick up all types of errors (Some errors only occur when
the express is run against an XML instance).
Use the 'Compile' method of the XPathNavigator to return a compiled
XPathExpression. This method call will result in an XPathException if the
XPath expression is invalid, you can handle the exception in your code. Note
that this is only a 'static' check and will not pick up errors such as
missing namespace context etc.
A regular expression wouldn't do because of the composability of XPath
(nested predicates and functions and so on).
> > Is there a way of validating and XPath? In this case , I am
> > accepting an XPath from the user and I need to validate the XPath
[quoted text clipped - 7 lines]
> to check the W3C web site whether an applet checking XPath 1.0 is
> available too.