When defining a schema for a particular class of documents, you specify which elements and attributes are allowed in a complying XML document, and how those elements and attributes are related to each other. In an XML-Data Reduced (XDR) schema, you define elements and attributes by specifying an <ElementType> element and an <AttributeType> element, respectively. You can then declare an instance of an element or an attribute using <element> or <attribute> element tags.
The following example shows an XDR schema that uses the <ElementType> element to define four elements: <title>, <author>, <pages>, and <book>. The definition of the <book> element includes the content model for that element, which specifies that each <book> element contains <title>, <author>, and <pages> child elements. This content model is specified using an <element> element with a type attribute that references the element type defined earlier.
The schema also defines the copyright attribute for the <book> element by using the <AttributeType> element. Then the schema declares the attribute using the <attribute> element.
XDR Schema File (abovefile.xml)
<?xml version="1.0"?> <Schema xmlns="urn:schemas-microsoft-com:xml-data"> <ElementTypename="title"/> <ElementTypename="author"/> <ElementTypename="pages"/> <ElementTypename="book" model="closed"> <elementtype="title"/> <elementtype="author"/> <elementtype="pages"/> <AttributeTypename="copyright"/> <attributetype="copyright"/> </ElementType> </Schema>
<r xmlns:a="x-schema:abovefile.xml"> <a:book copyright=""> <a:title/> <a:author/> <a:pages/> </a:book> </r>
You can specify the <AttributeType> element globally by placing it outside the context of any <ElementType> element. This allows multiple elements to share the definition of a common attribute.
The following example shows an XDR schema with multiple elements that share the definition of the copyright attribute.
XDR Schema File (abovefile.xml)
<?xml version="1.0"?> <Schema xmlns="schemas-microsoft-com:xml-data"> <ElementType name="title"/> <ElementType name="author"/> <ElementType name="pages"/> <AttributeTypename="copyright"/> <ElementType name="book" model="closed"> <element type="title"/> <element type="author"/> <element type="pages"/> <attributetype="copyright"/> </ElementType> </Schema>
<r xmlns:a="x-schema:abovefile.xml"> <a:book copyright=""> <a:title/> <a:author/> <a:pages/> </a:book> </r>
| This HTML Help has been published using the chm2web software. |