W3C home > Mailing lists > Public > xmlschema-dev@w3.org > February 2003

Re: Finding root element..

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
Message-ID: <OF3F5C1297.D81A4202-ON85256CD5.0009FE59@lotus.com>

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:



- and - 



Now we can make it fancier:

<xsd:element name="a">
                        <element ref="b"/>
<xsd:element name="b"/>

Ah, you say, now surely "a" is the root?  Not necessarily.  This schema 
will validate:



- and - 



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

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:15:09 UTC