[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 5
This section has received much rougher treatment. A paragraph at the top explains the mostly undetermined issues of putting content model declarations inside XSC:XSchema elements. All elements now have (optional) id attributes for easy reference. I also cleaned out a lot of odd conditional language. 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. 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. 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> <!ATTLIST XSC:Empty id ID #IMPLIED> For example, to declare the Species element shown in the previous section empty, use the following XSchema declaration: <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> <!ATTLIST XSC: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: <XSC:ElementDecl name="Species"> <XSC:Any/> </XSC: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 XSC:PCData EMPTY> <!ATTLIST XSC: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: <XSC:ElementDecl name="Species"> <XSC:PCData/> </XSC: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. 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 id ID #IMPLIED Element NMTOKEN #REQUIRED Frequency (Required | Optional | ZeroOrMore | OneOrMore) 'Required'> The Element attribute must refer to the Name attribute of an XSC:ElementDecl element elsewhere in the XSchema document. An XSC:ElementDecl element may contain at most one XSC: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: <XSC:ElementDecl name="Species"> <XSC:Ref Element="CommonName" Frequency="Required"/> </XSC: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': <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> 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 XSC:Ref elements nested within the XSC:Mixed declaration. Only XSC:Ref elements can be nested under an XSC:Mixed element; the PCData content is inherent in the Mixed content model. <!ELEMENT XSC:Mixed (XSC:Ref+)> <!ATTLIST XSC: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: <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 XSC:Ref elements that appear as subelements of the XSC: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 XSC:Choice element may 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. <!-- A Choice must have two or more children --> <!ELEMENT XSC:Choice ((Seq | Ref), (Seq | Ref)+)> <!ATTLIST XSC:Choice id ID #IMPLIED Frequency (Required | Optional | ZeroOrMore | OneOrMore) 'Required'> The simplest XSC:Choice element will contain two Ref elements and a frequency attribute. By default, the XSC: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: <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. 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. <!-- A Seq must have two or more children --> <!ELEMENT XSC:Seq ((Choice | Ref),(Choice | Ref)+)> <!ATTLIST XSC:Seq id ID #IMPLIED Frequency (Required | Optional | ZeroOrMore | OneOrMore) 'Required'> The simplest XSC:Seq element will contain two Ref elements in the order in which they should appear and a frequency attribute. By default, the XSC: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: <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@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
|