You can verify an XPath expression against an XML doc to verify it, but is there an easy way to verify the same XPath expression against the schema for that document?
Say I have an XSD schema like this:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" ... etc>
<xsd:element name="RootData">
<xsd:complexType>
<xsd:sequence minOccurs="0">
<xsd:element name="FirstChild">
<xsd:complexType>
<xsd:sequence minOccurs="0">
<xsd:element name="FirstGrandChild">
... etc etc
Is there an easy or built-in way to verify that the XPath:
/RootData/FirstChild/FirstGrandChild
would be valid against any XML documents that may be based on that schema? (Edit: I guess I mean potentially valid; the actual XML document might not contain those elements, but that XPath could still be considered potentially valid for the schema. Whereas, say, /RootData/ClearlyInvalidChild/ThisElementDoesntExistEither
is clearly invalid.)
Of course I could only expect this to work against canonical XPath expressions rather than ones of arbitrary complexity, but that's fine.
I'm specifically thinking in .NET but am curious if other implementations make it possible. It's not so important that I want to roll my own, for example I don't really want to write my own code to transform that XPath expression into another one like:
/xsd:schema/xsd:element[@name='RootData']/xsd:complexType/xsd:sequence/xsd:element[@name='FirstChild']/...etc...
... though I know I could do that if I really had to.
Cheers!