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 4

[ 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: Thu, 9 Jul 98 20:34:33 UT

This is mostly minor cleanup.  The examples still referred to the id attribute 
of the element, not its name, which could be disastrous now that we're giving 
elements id attributes separately.

Big question: Do we give these elements id attributes as well?  It seems like 
overkill to me, but I can imagine cases where it might be worth it.

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 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 name="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 name="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 name="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 name in an ElementDecl element -->
<!ATTLIST XSC:Ref
    Element NMTOKEN #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 name="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 name="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 name="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 name="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 or one of the elements referenced by an XSC:Ref element nested 
within the XSC:Mixed declaration.

<!ELEMENT XSC:Mixed (XSC:Ref+)>
<!ATTLIST XSC:Mixed
    Frequency (ZeroOrMore) #FIXED "ZeroOrMore">

If the Species element were to contain a mix of PCData, CommonName elements, 
LatinName elements, and PreferredFood elements in any order, the declaration 
would look like:

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

The XSchema processor should ignore any frequency attributes in the Ref 
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. 

<!-- 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 name="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 sub-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 name="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@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