« Operating at the XML Message Level in JAX-WS 2.0 | Main | Generating XML files from XML Schema »

April 04, 2006

First ideas about validating XPath expressions againt XML Schema

Using XPath expressions to access certain nodes in a document-oriented SOAP message is a good idea.

A problem may be that you don't know if the XPath expressions really match a node in the SOAP message, especially if interfaces and message structure are changed (see Changing interfaces with RPC and document-oriented style).

You don't know that an XPath expression is invalid until run-time. One concept should be to be able to do validation of XPath expressions at compile time (i.e. more loosely coupled, early binding). Here are some ideas how this can be gained:

  1. Creating an empty XML document from the XPath expression. Then use an XML validator to validate this against an XML Schema. (Problem: That XML document is not a complete document but only contains the nodes from the XPath expression)
  2. Creating an empty XML document from the XML Schema definition. Then use the XPath expression to get a certain node and see if it exists. (Problem: How complicate is it to create an empty XML document from the Schema? How many Schema elements and constructs need to be supported? E.g. specific data types are irrelevant for XPath expressions, are they?)
  3. Write a program that parses the XPath expression and walk along the Schema to see if the expression could be valid (Sounds very complicated)

Posted by Dominik Marks at April 4, 2006 04:33 PM

Comments

The second approach seems to be feasible. Given that XML Schema's type system offers a vast amount of possibilities, restrictions and constraints it is very difficult to generate a representative document from a schema. On the other hand this approach would also help to support the creation of valid documents, which is much more difficult to achieve in programming languages such as Java or C# than accessing XML documents. At least when using means which adhere to the programming paradigm of Java & C#.

Posted by: Hartmut at April 5, 2006 10:55 AM

Data types are irrelevant for XPath -- but of course not for the programming language ;-) E.g. if your XPath expression resolves to an attribute value, that attribute's type should still match the programming language type you're mapping to.

I suggest you take a look at Xerces 2.6's XML Schema support to see how hard it is to construct valid "paths" through a schema -- I somehow fear option 3 is the one you'll have to go with. But I'm honestly not sure.

Posted by: Stefan Tilkov at April 5, 2006 03:03 PM

Some more thoughts about the options:


Option 1: Won't work because it is impossible to reconstruct a whole XML document from a XPath expression


Option 2: Difficult to create an XML document from a Schema, but not impossible. It depends on how complete XML Schema needs to be supported for the task "Verifying XPath expressions".


Option 3: Sounds even more difficult than option 2. You have to parse and understand XPath and XML Schema!! This depends on how complete all XPath constructs needs to be supported, too.


I tried option 2 a bit and had some success so far. If it fails I will think about option 3 or think of other options.

Posted by: Dominik Marks at April 5, 2006 03:35 PM

Post a comment




Remember Me?

(you may use HTML tags for style)