|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV |
TODAY'S TOP SOA & WEBSERVICES LINKS Desperately Seeking...Help for XML Schema
Desperately Seeking...Help for XML Schema
By: Tom Gaven
May. 30, 2002 12:00 AM
Whether it's the Russian dolls, Salami Slices, or Chameleon Schemas discussed at www.xfront.com, the dizzying array of elements and attributes (and their complex interactions) found in the XML Schema specification, or the multitude of UML stereotypes at www.xmlmodeling.com, W3C XML Schema will disappear into oblivion without a non-XML syntax and a set of easy-to-use and -understand best practices and modeling techniques. There's been a lot of interest in XML Schema, and well there should be. A lot of very smart people put the XML Schema spec together, and I'm sure it took an amazing amount of effort. But if I can be frank for a moment, XML Schema is rocket science. From noNamespaceSchemaLocation to block attributes and substitutionGroups, the XML Schema syntax is simply too complex....STOP the MADNESS and just say NO! While I fault the XML Namespace Recommendation for many of the complexities haunting the XML Schema Spec today, many of the wounds are self-inflicted. One (small) case in point is XML Schema - complexType Inheritance.
complexType Inheritance Is Simply Broken
Why? complexType inheritance has two major limitations:
Let's assume I have a complexType called XType.
<xsd:complexType name="XType" > That is, XType has a content model of (a,b,c). For simplicity I'll use DTD syntax here to demonstrate the problem. (It's unfortunate that I need to resort to DTD syntax to discuss a problem with XML Schema...but I digress.)
Now let's say I wanted to reuse the parent type XType, and model several "subtypes" that correspond to the following content models:
Unfortunately, only No. 1 above can be modeled using complexType inheritance. That is, a child type can extend the parent's type only "to the right." Moreover, the child type can extend the parent type only with a sequence...that is, a comma between the parent and child definition. (Even No. 3 above, which uses a sequence, is invalid because of the grouping of the child's model with the parent's model.) Of course, we can support Nos. 1-7 above, and get all the reusability we want with XML Schema model groups. But the problem here is that I can't just throw away the complexType syntax and replace it with model group syntax. If I use model groups, I have to complicate my XML Schema document even more. This is probably why many tutorials on XML Schema avoid discussing model groups altogether, which is unfortunate, because model groups are the best way to get flexibility and reuse with XML Schema. Another restriction of complexType inheritance is that it doesn't support multiple inheritance. Model groups, however, can be used to coalesce any number of other model groups in reusable combinations. But wait a minute, you say, isn't complexType inheritance useful for other things besides reuse, like "polymorphism" or base type "restriction"? Well, yes, that's true, but they're also broken. To achieve base type restriction with XML Schema, we have to duplicate the entire content model of the parent type in the child's type definition. Yes, that's right, you have to copy and paste the parent's definition into the child! Say whaaat?!!?? To achieve polymorphism with XML Schema, we have to place xsi:type attributes in our instance documents. This means that document authors and designers are forced to use attributes dictated by the W3C in their business vocabularies! It also forces much complexity on the programmers trying to process these documents. Doesn't this fly in the face of what XML is all about?
Desperately Seeking...
Desperately Seeking...
<course name="XML Schema, Distilled" > And here's a complete compact schema document that can be used to ultimately validate the XML instance document above (using James Clark's compact syntax for RELAX NG):
start = course One thing to note is that the schema above is seven lines shorter than the equivalent DTD...and look, mom, no parameter entities!
Desperately Seeking...
SIDEBAR
YOUR FEEDBACK
XML JOURNAL LATEST STORIES . . .
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK BREAKING XML NEWS |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||