XSchema Spec Section 2.3, Draft 1
Simon St.Laurent
SimonStL at classic.msn.com
Thu Jun 11 18:44:01 BST 1998
This one is much longer than its predecessors, for which I apologize.
Section 2.3 defines the Content Model Declarations, which presently appear as
sub-elements of the Element Declaration. This section is based on the unified
John Cowan/Ron Bourret DTD, except that I added PCData back into the Mixed
Declaration.
All comments, suggestions, alternative proposals, and giggles are welcome. I
haven't had time to modify this for suggestions made about section 2.2.
Hopefully I'll be able to put it together next week.
I hope to have 2.4 on attributes out tomorrow or possibly Saturday, depending
on how quickly I can write a chapter on Proxy Servers that's due tomorrow.
I'm moving from Greensboro, NC, to Ithaca, NY on Monday, so my communications
will be more intermittent than usual. It's difficult to check email while
driving a U-Haul truck, and I don't have a cellular modem or phone anyway.
Simon St.Laurent
Dynamic HTML: A Primer / XML: A Primer / Cookies
------------------------
2.3 Content Model Declarations
Content model declarations are made within the declaration for the element to
which they apply.
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 XSC:Empty element
indicates that an element is empty.
<!ELEMENT XSC:Empty EMPTY>
If the Species element shown in the previous section were to be declared as
empty, the XSchema declaration for that element would look like:
<XSC:ElementDecl id="Species">
<XSC:Empty/>
</XSC: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 XSC:Any EMPTY>
Using the Any content model is much like using the Empty content model. If the
Species element had a content model of any, the XSchema declaration for the
Species element would look like:
<XSC:ElementDecl id="Species">
<XSC:Any/>
</XSC:ElementDecl>
This would allow 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 XSC:PCData EMPTY>
Using the PCData content model is much like using the Empty and Any content
models. If the Species element had a content model of PCData, the XSchema
declaration for the Species element would look like:
<XSC:ElementDecl id="Species">
<XSC:PCData/>
</XSC:ElementDecl>
This would allow 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. XSC:Ref elements identify the
element to be contained, as well as the frequency with which it must appear:
<!ELEMENT XSC:Ref EMPTY>
<!-- Element references the id in an ElementDecl element -->
<!ATTLIST XSC:Ref
Element IDREF #REQUIRED
Frequency (Required | Optional | ZeroOrMore | OneOrMore) 'Required'>
An XSC:ElementDecl element may contain only a single XSC:Ref element. 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.
If the Species element were to contain a single CommonName element, and
nothing else, the declaration would look like:
<XSC:ElementDecl id="Species">
<XSC:Ref Element="CommonName" Frequency="Required"/>
</XSC:ElementDecl>
This would require 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':
<XSC:ElementDecl id="Species">
<XSC:Ref Element="CommonName" Frequency="Optional"/>
</XSC: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':
<XSC:ElementDecl id="Species">
<XSC:Ref Element="CommonName" Frequency="OneOrMore"/>
</XSC: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':
<XSC:ElementDecl id="Species">
<XSC:Ref Element="CommonName" Frequency="ZeroOrMore"/>
</XSC:ElementDecl>
OneOrMore is the equivalent of the * occurrence indicator in XML 1.0 DTDs.
2.3.6 Mixed Content Model
Mixed content models allow the unordered use of different element types and
character data. Content within an element that uses a mixed declaration must
be PCData (if PCData is declared) or one of the elements referenced by an
XSC:Ref element nested within the XSC:Mixed declaration.
<!ELEMENT XSC:Mixed (XSC:PCData?, XSC:Ref+)>
If the Species element were to contain a mix of CommonName elements, LatinName
elements, and PreferredFood elements in any order, the declaration would look
like:
<XSC:ElementDecl id="Species">
<XSC:Mixed>
<XSC:Ref Element="CommonName"/>
<XSC:Ref Element="LatinName"/>
<XSC:Ref Element="PreferredFood"/>
</XSC:Mixed>
</XSC:ElementDecl>
If the Species element were to allow PCData as well as those declarations, the
PCData element must appear first in the listing:
<XSC:ElementDecl id="Species">
<XSC:Mixed>
<XSC:PCData/>
<XSC:Ref Element="CommonName"/>
<XSC:Ref Element="LatinName"/>
<XSC:Ref Element="PreferredFood"/>
</XSC:Mixed>
</XSC:ElementDecl>
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.
<!-- A Choice must have two or more children -->
<!ELEMENT XSC:Choice ((Seq | Ref), (Seq | Ref)+)>
<!ATTLIST XSC:Choice
Frequency (Required | Optional | ZeroOrMore | OneOrMore) 'Required'>
At its simplest, an XSC:Choice element will contain two Ref elements and a
frequency attribute. The XSC:Choice element may also indicate a frequency,
allowing the content model defined by the XSC:Choice model to appear one, one
or zero, one or more, or zero or more times. By default, the XSC:Choice
element's content model is required to appear once.
If the Species element were to allow either a Common Name or a Latin Name, but
not both, the following declaration would be appropriate:
<XSC:ElementDecl id="Species">
<XSC:Choice Frequency="Required">
<XSC:Ref Element="CommonName"/>
<XSC:Ref Element="LatinName"/>
</XSC:Choice>
</XSC:ElementDecl>
The XSC:Ref elements in an XSC:Choice element may also specify the frequency
with which they appear, as may the XSC:Seq elements described in section
2.3.8. The XSC:Choice element is the equivalent of the choice group (element |
element) in XML 1.0 DTDs. The ordering of the XSC:Ref elements within an
XSC: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 XSC:Choice and XSC:Ref sub-elements in the XSC:Seq element.
<!-- A Seq must have two or more children -->
<!ELEMENT XSC:Seq ((Choice | Ref),(Choice | Ref)+)>
<!ATTLIST XSC:Seq
Frequency (Required | Optional | ZeroOrMore | OneOrMore) 'Required'>
At its simplest, an XSC:Seq element will contain two Ref elements in the order
in which they should appear and a frequency attribute. The XSC:Seq element may
also indicate a frequency, allowing the content model defined by the XSC:Seq
model to appear one, one or zero, one or more, or zero or more times. By
default, the XSC:Seq element's content model is required to appear once.
If the Species element were to require a Common Name and a Latin Name, in that
order, the following declaration would be appropriate:
<XSC:ElementDecl id="Species">
<XSC:Seq Frequency="Required">
<XSC:Ref Element="CommonName"/>
<XSC:Ref Element="LatinName"/>
</XSC:Seq>
</XSC:ElementDecl>
The XSC:Ref elements in an XSC:Seq element may also specify the frequency with
which they appear, as may the XSC:Choice elements. The XSC: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 at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/
To (un)subscribe, mailto:majordomo at ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at ic.ac.uk)
More information about the Xml-dev
mailing list