More on using global element decls

Randy commented on yesterday's post about how I use XSD. He doesn't like the use of multiple global element decls because it makes it unclear which one or ones can be used as the root of a document. I like the GED-centric model because I often want to reuse chunks of XML in multiple places and it feels like the best way to do that.

There is a larger point here, though. I've found in my work that I often want to apply schema for completely different tasks: authoring and validation. Randy's concern is about authoring; making it easy for people to write an instance in XMLSpy or another schema-aware editor. To that end, he wants one GED. I want multiple GEDs because then I can validate any subtree of an instance doc. The real solution to this is actually to do both. We could write two separate schemas, one with multiple GEDs for me and one with a single GED and qualified local element decls (LED) for Randy, that describe the same language.

I've actually taken this path before, writing multiple schemas to validate different aspects of a document at different points in a system. The alternative was to modify the instance document during processing in order to change schema affiliation by redefining the root element or overriding type affiliation using xsi:type. That approach seemed wrong and expensive, so we wrote multiple schemas for the same language instead. The multiple-schema approach works quite well, except that most developers - and the tools they use - don't expect it. Unfortunately, it's hard to write a schema to meet all needs because goals and tools differ. We ended up going back to a single very open schema and a lot of extra validation code written other ways. (One of the things I like about RelaxNG is that there doesn't seem to be the same expectation that there be a single definitive schema for a given language. This is a good thing, but even with RNG, it would be a big shift for people to make.)

If I have to choose between one GED for authoring and many for processing, I'd go with many because I can provide guidance to authors about which GED they should use as their root element(s) other ways. The reverse is not true.


Posted Aug 25 2004, 06:51 AM by tim-ewald

Comments

Confluence: XFire wrote XML Schema Best Practices
on 08-25-2004 6:51 AM
How should we be writing our types? That is the question. As schema groups and then reference them as complex types?See A relaxing approach to XSD|http://pluralsight.com/blogs/tewald/archive/2004/08/24/2020.aspx and a followup|http://pluralsight....
The XML Files wrote XSD Can Make Us Happy
on 08-25-2004 11:45 AM
Randy Charles Morin wrote re: More on using global element decls
on 08-30-2004 8:40 PM
I've done this many times in the past, most recently when I wrote the Atom XSDs. In this case, I wrote a strict and lax XSD, one for validation and one for use by XSD-based tools like XSDObjectGen. I'm not certain this is a good practice.

http://www.kbcafe.com/rss/?guid=20040830213422
Confluence: XFire wrote Designing Web Services
on 11-09-2004 10:46 AM
Over the last several years we've learned a lot about web services. What to do and what not to do. This section should help piece some of that together and provide a set of best practices. Web Services Are Not Objects RPC/Encoded vs....

Add a Comment

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