xmlxpathspecifications

Where is the official specification for XPath syntax?


I want to write a function that simply validates the syntax of an XPath expression independent of any XML/HTML (so it would catch something like //p[text(}="Hello"] as having a typo), but I can't seem to find a full fledged XPath specification.

Follow Up: It seems I should follow up so people don't think I'm crazy. I'm trying to write a Rust procedural macro for catching malformed xpaths at compile time, as sort of a convenience feature to build into Rust Selenium bindings (see thirtyfour or fantoccini on crates.io) so that one doesn't have to get 20 minutes into their test suite before Selenium crashes to tell them they have a typo like with the other language bindings. I'll probably end up doing FFI out to a well-maintained library in another language (actually https://crates.io/crates/libxml might do the trick), but I thought I'd at least see what the workload would be to write this myself.


Solution

  • The W3C XPath Recommendations are the official specifications for XPath:

    If you must write an XPath parser from scratch, at least one of those will be necessary reading. If you do not really need to write an XPath parser from scratch, you might simply use an existing library and examine the return value or catch any parsing exceptions to determine the well-formedness of the passed XPath expression.