OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Define a root in a DTD




> I've seen schema proposals that let you specify which of a schema's
> element types could be a document's root element, but after a quick look
> at section 3.3 of Part 1 of the W3C Schema Rec
> (http://www.w3.org/TR/xmlschema-1/#cElement_Declarations) and the RELAX NG
> schema for RELAX, I don't believe that either of these let you do this. I
> could be wrong.

A RELAX NG schema always specifies what the allowed root (ie document) 
elements are. For example, if your schema is:

<element name="list">
  <zeroOrMore>
    <element name="item">
      <text/>
    </element>
  </zeroOrMore>
</element>

then only <list> is possible as a root element.  In a more complex case, 
you would typically use the <grammar> element, and then the <start> element 
specifies the root:

<grammar>

<start>
  <ref name="List"/>
</start>

<define name="List">
  <element name="list">
    <zeroOrMore>
      <ref name="Item"/>
    </zeroOrMore>
  </element>
</define>

<define name="Item">
  <element name="item">
    <text/>
  </element>
</define>

</grammar>

However, you are not restricted to specifying a single element as a root. 
You could have a <choice> of more than one element.

<start>
  <choice>
    <ref name="List"/>
    <ref name="Item"/>
  </choice>
</start>

You still have the same flexibility that you have with DTDs because of 
RELAX NG's <include> mechanism.  When you include the grammar you can 
replace the start by putting the replacement <start> inside the <include> 
(a bit like with a DTD internal subset):

<grammar>

<include href="list.rng">
  <start>
    <ref name="Item"/>
  </start>
</include>

</grammar>

Alternatively, you can create a <grammar> without a <start>:

<grammar>

<define name="List">
  <element name="list">
    <zeroOrMore>
      <ref name="Item"/>
    </zeroOrMore>
  </element>
</define>

<define name="Item">
  <element name="item">
    <text/>
  </element>
</define>

</grammar>

and then specify the start when you include it in another grammar:

<grammar>

<include href="list.rng"/>

<start>
  <ref name="List"/>
</start>

</grammar>

James