- From: Noah Mendelsohn/Cambridge/IBM <noah_mendelsohn@us.ibm.com>
- Date: Fri, 21 Feb 2003 20:53:12 -0500
- To: Kevin Hanna <kevin@hanna.net>
- Cc: xmlschema-dev@w3.org
Kevin Hanna asks:
>> Has anybody come up with a fail proof way to
>> find the root element in *any* XSD?
Well, for better or worse, that's not quite how xml schema works.
The following schema, is just fine:
<xsd:element name="a"/>
<xsd:element name="b"/>
It will potentially evaluate:
doc1:
<a/>
- and -
doc2:
<b/>
Now we can make it fancier:
<xsd:element name="a">
<xsd:complexType>
<xsd:sequence>
<element ref="b"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="b"/>
Ah, you say, now surely "a" is the root? Not necessarily. This schema
will validate:
doc1:
<a>
<b/>
</a>
- and -
doc2:
<b/>
Bottom line: any global element can serve as the root of a validation,
whether or not that element is used as another's content.
I'm sure you're going to ask: why? Well, among the reasons is that
schema is designed to support validation of fragements, free-standing
elements, etc. We don't necessarily distinguish the free standing "b" in
doc 2 from the nested one in doc 1. You can validate either one on its
own, presuming your processor is written to let you start with a nested
element. Also: there are vocabularies in which it's handy to define one
whole namespace in a single schema document, but in which the voculary
supports two different types of document (request and response, perhaps).
Anyway, that's how it works. (By the way, I somewhat simplified the
explanation of the examples. The elements declared without explicit type
are implictly of anytype, and each of them could have allowed children,
which I didn't show.)
------------------------------------------------------------------
Noah Mendelsohn Voice: 1-617-693-4036
IBM Corporation Fax: 1-617-693-8676
One Rogers Street
Cambridge, MA 02142
------------------------------------------------------------------
Received on Friday, 21 February 2003 20:57:03 UTC