I have come across a situation where I want to make sure that an XPath expression is valid for querying a document that conforms to a specific XML Schema. My first thought was: this must have been done before and I started googling. I found some discouraging discussions. One approach was to create a dummy document from the schema and then try to evaluate the XPath expression. Nice try, but not ideal.
The XPath expressions I want to validate are actually very simple: they are absolute location paths and so far I’ve only seen elements (including namespace prefix) as nodes. I was thinking of using the XPath parsing in REXML but that’s clearly overkill when the XPath expressions are so simple. Keep It Simple, Stupid! I wonder if such a validation could be written in an XSLT that traverses the XML Schema?