Microsoft XML Core Services (MSXML) 4.0 - XML Schemas

Specifying the Content Model of an Element

When specifying the content model of an element, you must perform the following tasks.

Example

The following example describes the content model and elements for an XDR schema.

XDR Schema File (BookSchema.xml)

<s:Schema xmlns:s="urn:schemas-microsoft-com:xml-data">
  <s:ElementType name="title" content="mixed"/>
  <s:ElementType name="authors" content="textOnly"/>
  <s:ElementType name="pages" content="textOnly"/>
  <s:ElementType name="book" order="seq" content="eltOnly">
    <s:element type="pages"/>
    <s:element type="title"/>
    <s:element type="authors"/>
  </s:ElementType>
</s:Schema>

The content model for the <title>, <author>, and <pages> elements is straightforward. Because the content attribute specifies the elements as "textOnly", these elements contain only text and nothing else (that is, no child elements).

The content model for the <book> element is more complex. The value of the content attribute for the <book> element is "eltOnly". This means that the <book> element can contain only the elements specified (<title>, <author>, and <pages>) in the schema. Furthermore, for each <book> element instance in the document, the child elements must be in the order specified in the schema. This order is validated by setting the order attribute of the to the value of "seq".

The following is a valid instance of the XML document.

<x:book xmlns:x="x-schema:BookSchema.xml">
  <x:pages>474</x:pages>
  <x:title>Applied XML: A Toolkit for Programmers</x:title>
  <x:authors>Alex Ceponkus and Faraz Hoodbhoy</x:authors>
<x:/book>
Note   Elements with content="empty" and model="open" are not allowed.

See Also

content Attribute | <group> Element | minLength and maxLength Attribute | minOccurs and maxOccurs Attribute | model Attribute (Open and Closed Content Models) | order Attribute

This HTML Help has been published using the chm2web software.