Re: Is there an indicator or constraint on the root element?

At 2001-03-07 10:08, Zhang, Tao wrote:
>Hi,
>
>Is there a standard way to indicate which of the top-level defined elements
>in the Schema is the
>real root element in the instance XML document? And this indication can be
>catched by a program
>when processing only the Schema. And is there a constraint that other
>top-level defined elements,
>if not root element in the instance XML document, must be referred by later
>defined elements?

No, there is not.  This was discussed during design (issue 126 in the
issues list from the main design phase [IL]), and the sentiment of the WG
was (as nearly as I can reconstruct) that it would be better not to
have a schema specify a root element for several reasons:

   - schema validation is not required to start at the root element of
     the document, or at any particular element:  the choice of the
     element at which to begin validation is a matter for negotiation,
     as it were, between implementation and user.
   - depending on the way in which schemas are composed, there may be
     more than one element type which is suitable for use as the root
     element of a document, or as the outermost element in its namespace
     (i.e. as an element which may suitably appear in the content model
     of an element type declared in a different namespace)

[IL] http://www.w3.org/XML/Group/xmlschema-current/issues.html#startSymbol
(Member-only link)

Experience with DTDs supports at least the second point:  it is not
hard to find DTDs which have several potential root elements, each
suitable for different uses.  The document type declaration, by giving
the root, signals which element type to use as the root, but since
that element is also given by the start- and end-tags for the root
element of the document, this information is, strictly speaking,
redundant.

>For example, consider this Schema file and suppose there is no instance XML
>files available:...
>It seems there is not way to tell whether it is "purchaseOrder"or "comments"
>the real root element
>in the instance XML file.

Correct.  Any top-level element type can be used as the root of a
document or of a validation episode, or as the child of an element type
in a different namespace.

I hope this helps.

-C. M. Sperberg-McQueen

Received on Wednesday, 7 March 2001 13:54:57 UTC