Attempting to address Rajesh's concerns about optionality...

My last post on optional content triggered a conversation between Rajesh and Jon. Rajesh's main concern is that making almost everything in your schema optional may give you flexibility, but if occurence requirements aren't captured somewhere, then its hard to consume a service (or other XML). That's true - you need to know what's required. The problem is that if you put that info in your schema, and then you need to change it and that requires changing your namespace, then you have a problem. I can see two possible solutions. One is to include occurence info in your schema but make it clear to everyone that you feel free to change it without changing your target namespace. The big issue here is that if you have an XSD used by multiple services that have different occurence constraints, what do you do? You could combine all the requirements and express the weakest, but keeping that up to date over time would be hard. You could have two different copies of the schema, each with different occurence requirements, but then how does the consumer generate code from both in a meaningful way? You could solve this problem by using a common schema with everything optional, and then offering a per-service redefinition of the schema with specific occurence constraints. xsd:redefine would handle that nicely, but you need the tools to know that they're supposed to generate code from the core schema referenced by the redefine. Since none of the mainstream code-gen tools handle redefine, that seems like a dead-end (which is too bad because it *does* capture the semantics nicely). No, I still think you're better off focusing your schema on describing the shape of data, if it is present, and captureing the current rules for what must be present some other way, e.g., documentation. Increasingly, I think of this as a sort of hybrid of static and dynamic typing. At development time, you get enough info to statically compile your code and not be way off base (as you could be with Process(string xml)). But the system is dynamic enough to allow wiggle-room at run-time to compensate for service evolution.

Posted May 05 2006, 02:16 PM by tim-ewald

Comments

David wrote re: Attempting to address Rajesh's concerns about optionality...
on 05-05-2006 12:59 PM
One things I have seen (and used myself) is to put things like occurance as part of the XML *data* and not part of the XSD definition.

By convention you end up with your data elements with a set of defined meta attributes that go further than XSD can go in terms of restrictions and other 'higher level' business semantics. It's up to the xml client (and their documentation) to use it if they wish.

You then end up with a parseable data/metadata lump that can be consumed by whoever, and with less versioning hassles than trying to squeeze it into XSD. That's not to say it doesn't belong in there, it's like you said, few toolsets know how to handle code-gen off the main XSD path etc.

- David
Christopher Steen wrote Link Listing - May 5, 2006
on 05-05-2006 7:23 PM
Attempting to address Rajesh's concerns about
optionality... [Via: Tim Ewald ]
Axis2 1.0 released...
Rajesh wrote re: Attempting to address Rajesh's concerns about optionality...
on 05-10-2006 3:42 PM
Tim, first of all. Let me thank you for addresssing this very valuable topic.

Just to prove my point, please see comments (by Ebenezer Ikonne) in your post on "Versioning and semantic changes". You will see what I was saying in the previous posts. People just gravitate towards total openness which just kills me ;-)

to paraphrase............
think if "services" are build to accept "messages" i.e. ProcessMsg(Message msg), where the message is essentially xml (not typed), then the service can be evolved to support different messages, hence support/validate data supported by different schemas. So for the example that is presented above, we simply have two different messages that the service should be able to handle.

Regards
Rajesh
Ken Brubaker wrote Tim Ewald's solution for XML Schema versioning
on 11-28-2006 7:55 AM
Tim Ewald addresses the XML Schema versioning issue head on.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?