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

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   XSchema Spec - Content Model Declarations (Section 2.3), Draft 6

[ Lists Home | Date Index | Thread Index ]
  • From: "Simon St.Laurent" <SimonStL@classic.msn.com>
  • To: "Xml-Dev (E-mail)" <xml-dev@ic.ac.uk>
  • Date: Tue, 18 Aug 98 14:15:53 UT

Here's the latest content model declarations.  There are two big changes:

1) A Model element now contains the content model declarations.  This provides 
for documentation of the content model as a whole, and permits better 
(eventual) modularization.

2) All the XSC: prefixes have been stripped out per the new namespaces setup.

As always, a prettier HTML version of this will be posted shortly at 
http://purl.oclc.org/NET/xschema. 

Simon St.Laurent
Dynamic HTML: A Primer / XML: A Primer / Cookies


2.3 Content Model Declarations

Content model declarations are made within Model sub-element of the 
declaration for the element to which they apply. 

Reference, Mixed, Choice, and Sequence models may appear inside XSchema 
elements for reusability, documentation, and reference, but will need to be 
linked to particular element declarations through mechanisms not yet defined 
(most likely XLink). All content model declarations have an optional id value 
for reference.

The Model element holds the content model for an element.

<!ELEMENT Model (Doc?, More?, (Ref | Choice | Seq | Empty | Any | PCData | 
Mixed))>
<!ATTLIST Model 
       id ID #IMPLIED>

2.3.1 Empty Content Model

The simplest content model is empty, which indicates that the parent element 
has no sub-elements and no character data content. The Empty element indicates 
that an element is empty.

<!ELEMENT Empty EMPTY>
<!ATTLIST Empty
    id ID #IMPLIED>

For example, to declare the Species element shown in the previous section 
empty, use the following XSchema declaration:

<ElementDecl name="Species">
  <Model>
    <Empty/>
  </Model>
</ElementDecl>

This would not allow the Species element to contain any text or sub-elements.

2.3.2 Any Content Model

The Any content model, which allows the element to contain parsed character 
data or any other elements as content, is equally simple:

<!ELEMENT Any EMPTY>
<!ATTLIST Empty
    id ID #IMPLIED>

Using the Any content model is much like using the Empty content model. To 
declare that the Species element had a content model of any, use the following 
declaration:

<ElementDecl name="Species">
  <Model>
    <Any/> 
  </Model>
</ElementDecl>

This allows the Species element to contain text and any sub-elements an author 
desired.

2.3.3 PCData Content Model

The PCData content model, which allows the element to contain only parsed 
character data, is also represented by a single empty element.

<!ELEMENT PCData EMPTY>
<!ATTLIST Empty
    id ID #IMPLIED>

Using the PCData content model is much like using the Empty and Any content 
models. For example, to assign the Species element a content model of PCData, 
use the following declaration:

<ElementDecl name="Species">
  <Model>
    <PCData/> 
  </Model>
</ElementDecl>

This allows the Species element to contain text, but no sub-elements.

2.3.5 Reference Content Model

The Reference content model allows an element to specify other elements which 
it may contain, as well as their quantity. Ref elements identify the element 
to be contained, as well as the frequency with which it must appear:

<!ELEMENT Ref EMPTY>
<!-- Element references the name in an ElementDecl element -->
<!ATTLIST Ref
    id ID #IMPLIED
    Element NMTOKEN #REQUIRED
    Frequency (Required | Optional | ZeroOrMore | OneOrMore) 'Required'>

The Element attribute must refer to the Name attribute of an ElementDecl 
element elsewhere in the XSchema document. An ElementDecl element may contain 
at most one Ref element. 

The Frequency attribute controls the number of referenced elements that may 
occur. To define content models that permit or require the use of more 
elements, the Any, Mixed, Choice, or Sequence content models should be used as 
appropriate.
To declare that the Species element may contain a single CommonName element, 
and nothing else, use the following declaration:

<ElementDecl name="Species">
  <Model>
    <Ref Element="CommonName" Frequency="Required"/> 
  </Model>
</ElementDecl>

This requires the Species element to contain a single CommonName element. To 
make the CommonName element optional - though it may still only appear once, 
set the Frequency attribute to 'Optional':

<ElementDecl name="Species">
  <Model>
    <Ref Element="CommonName" Frequency="Optional"/> 
  </Model>
</ElementDecl>

Optional is the equivalent of the ? occurrence indicator in XML 1.0 DTDs.

To require the Species element to contain at least one but possibly multiple 
CommonName elements, set the Frequency attribute to 'OneOrMore':

<ElementDecl name="Species">
  <Model>
    <Ref Element="CommonName" Frequency="OneOrMore"/> 
  </Model>
</ElementDecl>

OneOrMore is the equivalent of the + occurrence indicator in XML 1.0 DTDs.

Finally, to allow the Species element to contain any number (including zero) 
of CommonName elements, set the Frequency attribute to 'ZeroOrMore':

<ElementDecl name="Species">
  <Model>
    <Ref Element="CommonName" Frequency="ZeroOrMore"/> 
  </Model>
</ElementDecl>

ZeroOrMore is the equivalent of the * occurrence indicator in XML 1.0 DTDs.

2.3.6 Mixed Content Model

Mixed content model allows the unordered use of different element types and 
character data. Content within an element that uses a mixed declaration must 
be PCData or one or more of the elements referenced by Ref elements nested 
within the Mixed declaration. Only Ref elements can be nested under an Mixed 
element; the PCData content is inherent in the Mixed content model.

<!ELEMENT Mixed (Ref+)>
<!ATTLIST Mixed
    id ID #IMPLIED
    Frequency (ZeroOrMore) #FIXED "ZeroOrMore">

To declare that the Species element may contain a mix of PCData, CommonName 
elements, LatinName elements, and PreferredFood elements in any order, use the 
following declaration:

<ElementDecl name="Species">
  <Model>
    <Mixed>
         <Ref Element="CommonName"/>
         <Ref Element="LatinName"/>
         <Ref Element="PreferredFood"/>
    </Mixed>
  </Model>
</ElementDecl>

The XSchema processor should ignore any frequency attributes in Ref elements 
that appear as subelements of the Mixed element.

2.3.7 Choice Content Model

The Choice content model allows for either-or inclusions of elements and 
groups of elements. The Choice content model represents groups of element 
content possibilities and must contain at least two sub-elements. Situations 
where only one element is needed should use the Ref content model instead of 
Choice. The Choice element may indicate a frequency, allowing the content 
model defined by the Choice model to appear one, one or zero, one or more, or 
zero or more times. 

<!-- A Choice must have two or more children -->
<!ELEMENT Choice ((Seq | Ref), (Seq | Ref)+)>
<!ATTLIST Choice 
    id ID #IMPLIED
    Frequency (Required | Optional | ZeroOrMore | OneOrMore) 'Required'>
The simplest Choice element will contain two Ref elements and a frequency 
attribute. By default, the Choice element's content model is required to 
appear once.

To declare that a Species element may contain either a common name or a Latin 
name, but not both, use the following declaration:

<ElementDecl name="Species">
  <Model>
    <Choice Frequency="Required">
         <Ref Element="CommonName"/>
         <Ref Element="LatinName"/>
    </Choice>
  </Model>
</ElementDecl>

The Ref elements in an Choice element may also specify the frequency with 
which they appear, as may the Seq elements described in section 2.3.8. The 
Choice element is the equivalent of the choice group (element | element) in 
XML 1.0 DTDs. The ordering of the sub-elements within an Choice element has no 
effect.

2.3.8 Sequence Content Model

The Sequence content model allows for the sequential appearance of 
sub-elements. Elements, if they are required to appear, must appear in the 
order of the Choice and Ref sub-elements in the Seq element. The Seq element 
may also indicate a frequency, allowing the content model defined by the Seq 
model to appear one, one or zero, one or more, or zero or more times.

<!-- A Seq must have two or more children -->
<!ELEMENT Seq ((Choice | Ref),(Choice | Ref)+)>
<!ATTLIST Seq 
    id ID #IMPLIED
    Frequency (Required | Optional | ZeroOrMore | OneOrMore) 'Required'>

The simplest Seq element will contain two Ref elements in the order in which 
they should appear and a frequency attribute. By default, the Seq element's 
content model is required to appear once.

To declare that the Species element requires a common name and a Latin name, 
in that order, use the following declaration:

<ElementDecl name="Species">
  <Model>
    <Seq Frequency="Required">
         <Ref Element="CommonName"/>
         <Ref Element="LatinName"/>
    </Seq>
  </Model>
</ElementDecl>

The Ref elements in an Seq element may also specify the frequency with which 
they appear, as may the Choice elements. The Seq element is the equivalent of 
the sequence group (element, element) in XML 1.0 DTDs.


xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/
To (un)subscribe, mailto:majordomo@ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo@ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@ic.ac.uk)





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS