[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] XSchema Spec - Content Model Declarations (Section 2.3), Draft 7
Here is what I hope to be the last round of revisions for the content model section. The Model element can now include Model subelements, as can Seq and Choice. 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 | Model))> <!ATTLIST Model id ID #IMPLIED> Model elements are pure containers, and act much like parentheses in XML 1.0 DTD declarations. If a Model element used as a part of a declaration contains content that is inappropriate to that declaration (for instance, a Mixed model in a Choice or Seq model), the processor should halt and signal a fatal error. 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 | Model), (Seq | Ref | Model)+)> <!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 | Model),(Choice | Ref | Model)+)> <!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. Simon St.Laurent Dynamic HTML: A Primer / XML: A Primer / Cookies xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@i... Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ To (un)subscribe, mailto:majordomo@i... the following message; (un)subscribe xml-dev To subscribe to the digests, mailto:majordomo@i... the following message; subscribe xml-dev-digest List coordinator, Henry Rzepa (mailto:rzepa@i...)
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|