| [ directory ] |
|
9.2 W3C XML SchemaAfter the XML Working Group (WG) successfully created XML 1.0, W3C formed the XML Schema WG in 1998. W3C XML Schema is the fruit of the three-year activity of this working group. Parts 0, 1, and 2 of W3C XML Schema were published as a W3C Recommendation in May 2001. Although W3C XML Schema is a powerful language, it is also a complicated language. Both proponents and opponents of W3C XML Schema exist in the XML community. It is hard to understand the full set of W3C XML Schema, and conformant implementations do not exhibit interoperability as of this writing. Moreover, since RELAX NG has been published by OASIS and then ISO/IEC JTC1, W3C XML Schema is not the only schema language for XML. However, W3C XML Schema does have some advantages over DTDs. Among them, we concentrate on datatypes and namespaces. This chapter does not try to cover all the features of W3C XML Schema. Those readers who are ambitious enough to try the full set of W3C XML Schema are referred to other books and to the W3C XML Schema Recommendation. 9.2.1 Mimicking DTDsThis section shows how DTD features can be mimicked in W3C XML Schema. Features specific to W3C XML Schema are covered later in this chapter. Element Type Declarations of DTDsWe use the simple XML document itemList.xml, shown in Listing 9.1, as an example. This document represents an item list (itemList) of items (item). Each item has two child elements: name and quantity. Listing 9.1 An item list document, chap09/itemList.xml
<?xml version="1.0" encoding="utf-8"?>
<itemList>
<item>
<name>pen</name>
<quantity>5</quantity>
</item>
<item>
<name>eraser</name>
<quantity>7</quantity>
</item>
<item>
<name>stapler</name>
<quantity>25</quantity>
</item>
</itemList>
We can create a DTD to formally describe which document represents item lists. Listing 9.2 shows an example of such a DTD called itemList.dtd. Listing 9.2 An item list DTD, chap09/itemList.dtd
<?xml version="1.0" encoding="utf-8"?>
<!-- A DTD describing list of items. -->
[4] <!ELEMENT itemList (item*)>
[5] <!ELEMENT item (name, quantity)>
[6] <!ELEMENT name (#PCDATA)>
[7] <!ELEMENT quantity (#PCDATA)>
This DTD has four element type declarations. The first element type declaration (line 4) specifies that elements of the tag name itemList contain zero or more elements of the tag name item. The second declaration (line 5) specifies that elements of the tag name item contain an element of the tag name name followed by an element of the tag name quantity. The other element type declarations (lines 6 and 7) specify the elements of the tag name name or quantity. The keyword #PCDATA shows that the contents of such elements are strings. Listing 9.3 shows a schema, itemList.xsd, written in W3C XML Schema that mimics the DTD itemList.dtd. Listing 9.3 A simple schema, chap09/itemList.xsd
<?xml version="1.0" encoding="utf-8"?>
[2] <xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
[4] <xsd:element name="itemList">
[5] <xsd:complexType>
[6] <xsd:sequence>
[7] <xsd:element ref="item"
[8] minOccurs="0" maxOccurs="unbounded"/>
[9] </xsd:sequence>
[10] </xsd:complexType>
</xsd:element>
[13] <xsd:element name="item">
[14] <xsd:complexType>
[15] <xsd:sequence>
[16] <xsd:element ref="name"/>
[17] <xsd:element ref="quantity"/>
[18] </xsd:sequence>
[19] </xsd:complexType>
</xsd:element>
[22] <xsd:element name="name" type="xsd:string"/>
[24] <xsd:element name="quantity" type="xsd:string"/>
</xsd:schema>
The root element (line 2) for a schema is xsd:schema. This element belongs to the namespace http://www.w3.org/2001/XMLSchema.[1] This schema contains four xsd:element elements (lines 4, 13, 22, and 24). The first and second xsd: element elements declare itemList and item, respectively. The content model (lines 14?9) of item is represented by xsd:complexType, xsd:sequence, and one xsd:element for name and another for quantity. The content model (lines 5?0) of itemList further uses the attributes minOccurs="0" and maxOccurs="unbounded". These attributes specify that an itemList can have zero or more item elements. The third and fourth xsd:element elements declare name and quantity, respectively. The attribute type="xsd:string" specifies that any string can be used as the value of name and quantity.
This schema can be referenced from a document, as shown in Listing 9.4, by specifying the attribute noNamespaceSchemaLocation, which belongs to the namespace "http://www.w3.org/2001/XMLSchema-instance". This attribute is merely a hint and is ignored when parsers are explicitly instructed to use another schema. Listing 9.4 Referencing a schema from a document, chap09/itemList-xsd.xml
<?xml version="1.0" encoding="utf-8"?>
<itemList
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation="itemList.xsd">
<item>
<name>pen</name>
<quantity>5</quantity>
</item>
<item>
<name>eraser</name>
<quantity>7</quantity>
</item>
<item>
<name>stapler</name>
<quantity>25</quantity>
</item>
</itemList>
Even when W3C XML Schema is used, application programmers using Xerces can write programs as usual. The only difference is that programmers have to specify the use of W3C XML Schema by invoking setFeature for DOM or SAX parsers. The following three statements specify the use of validation, namespaces, and W3C XML Schema, respectively. parser.setFeature( "http://xml.org/sax/features/validation", true); parser.setFeature( "http://xml.org/sax/features/namespaces", true); parser.setFeature( "http://apache.org/xml/features/validation/schema", true); If we run the program SimpleParseWithSchemaValidation (shown in Chapter 2, Listing 2.6), it parses this document and further validates it against itemList.xsd. Because the document is valid against the schema, this program reports no errors. Rather than specifying the attribute noNamespaceSchemaLocation in an XML document, we can explicitly instruct Xerces to reference certain schemas. We only have to invoke setProperty for DOM or SAX parsers.[2]
parser.setProperty(
"http://apache.org/xml/properties/schema/" +
"external-noNamespaceSchemaLocation",
"itemList.xsd");
Such programs do not require the attribute noNamespaceSchemaLocation in XML documents. Even if this attribute is specified, it is simply ignored. The schema specified by setProperty (in this example, itemList.xsd) is used. Attribute-List Declarations of DTDsNext, we introduce an attribute to this document. The item elements have the attribute number, as shown in Listing 9.5. Listing 9.5 Adding attributes to a document, chap09/itemList-attribute.xml
<?xml version="1.0" encoding="utf-8"?>
<itemList>
<item number="003">
<name>pen</name>
<quantity>5</quantity>
</item>
<item number="004">
<name>eraser</name>
<quantity>7</quantity>
</item>
<item number="009">
<name>stapler</name>
<quantity>25</quantity>
</item>
</itemList>
We have to update the DTD accordingly, as shown in Listing 9.6. An attribute-list declaration <!ATTLIST ....> for item is introduced (line 6). CDATA implies that any string may be used as a value of this attribute. Listing 9.6 An attribute-list declaration, chap09/itemList-attribute.dtd
<?xml version="1.0" encoding="utf-8"?>
<!-- A DTD describing list of items. -->
<!ELEMENT itemList (item*)>
<!ELEMENT item (name, quantity)>
[6] <!ATTLIST item number CDATA #REQUIRED>
<!ELEMENT name (#PCDATA)>
<!ELEMENT quantity (#PCDATA)>
We then revise our schema, itemList.xsd, and declare the attribute number for the item elements. The attribute-list declaration in the DTD is captured by <attributeGroup name="name" ...> and is referenced by <attributeGroup ref="name"/> within <complexType ...>, shown in Listing 9.7. Listing 9.7 Referencing the attribute-list declaration, chap09/itemList- attribute.xsd
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
<xsd:element name="itemList">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="item"
minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="item">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="name"/>
<xsd:element ref="quantity"/>
</xsd:sequence>
[19] <xsd:attributeGroup ref="item"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="quantity" type="xsd:string"/>
[27] <xsd:attributeGroup name="item">
[28] <xsd:attribute name="number" type="xsd:string"
use="required"/>
</xsd:attributeGroup>
</xsd:schema>
Within <attributeGroup name="name"...>, we declare attributes with <attribute ...>. Their name attribute specifies the attribute name, and the type attribute specifies a datatype. In this example, we have an attributeGroup (line 27), which is referenced at line 19. An attribute (line 28) declares an attribute. It specifies number and xsd:string as the attribute name and datatype, respectively, and further specifies that the declared attribute is required with use="required". Comments in SchemasComments contribute to the readability of schemas. Because it is very hard to guess the intention of schema authors, it is desirable to have many comments in a schema. W3C XML Schema provides <annotation><documentation>... </documentation></annotation> as a mechanism for representing comments. Almost all elements constructing schemas can have a comment as the first child. Unlike XML comments (that is, <!--...-->), it is clear that an <annotation> <documentation>...</documentation></annotation> element applies to its parent. The previous schema, to which we have introduced many comments, is shown in Listing 9.8. Listing 9.8 Adding comments to a schema, chap09/itemList-attribute-annotation.xsd
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
<xsd:annotation>
<xsd:documentation>The root of a schema</xsd:documentation>
</xsd:annotation>
<xsd:element name="itemList">
<xsd:annotation>
<xsd:documentation><!ELEMENT itemList (item*)>
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:annotation>
<xsd:documentation>This xsd:sequence is required.
</xsd:documentation>
</xsd:annotation>
<xsd:element ref="item"
minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>reference to item elements
</xsd:documentation>
<xsd:documentation>minOccurs="0" and
maxOccurs="unbounded" mimics "*"</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="item">
<xsd:annotation>
<xsd:documentation><!ELEMENT item (name, quantity)>
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="name"/>
<xsd:element ref="quantity"/>
</xsd:sequence>
<xsd:attributeGroup ref="item"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="name" type="xsd:string">
<xsd:annotation>
<xsd:documentation><!ELEMENT name (#PCDATA)>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="quantity" type="xsd:string">
<xsd:annotation>
<xsd:documentation><!ELEMENT quantity (#PCDATA)>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:attributeGroup name="item">
<xsd:annotation>
<xsd:documentation><!ATTLIST item number CDATA #IMPLIED>
</xsd:documentation>
</xsd:annotation>
<xsd:attribute name="number" type="xsd:string">
<xsd:annotation>
<xsd:documentation>number CDATA #IMPLIED>
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:attributeGroup>
</xsd:schema>
Table 9.1 summarizes how each construct of DTD can be mimicked in W3C XML Schema. We assume that the prefix xsd refers to the namespace http://www.w3.org/2001/XMLSchema.
9.2.2 DatatypesStrings in XML documents are often used to represent data such as integers, decimals, names, and dates. Such a string may appear as the content of an element or the value of an attribute. The datatypes of W3C XML Schema can ensure that element contents and attribute values correctly represent the data of specified datatypes. Using DatatypesA quantity element in the previous example represents the quantity of a type of item. Thus, permissible values are integers. Because DTDs do not provide any mechanisms for representing integers, it is impossible to specify that such elements contain integers rather than mere strings. On the other hand, W3C XML Schema provides very rich datatypes. For example, the datatype short provides integers greater than or equal to ?2768 and less than or equal to 32767. To specify that permissible values of quantity elements are short, we specify type="xsd:short" for the xsd:element for quantity, modifying line 24 of itemList.xsd as follows: <xsd:element name="quantity" type="xsd:short"/> Let us replace 5 in the first quantity element in Listing 9.4 with five. Then, SimpleParseWithSchemaValidation reports an error as follows:
R:\samples>java chap02.SimpleParseWithSchemaValidation
chap09/itemList-nonDigit-xsd.xml
[Error] 7:30 Datatype error: In element 'quantity' : 'five'
is not a decimal.
When a document is found to be invalid against a schema, a SAXParseException is raised. The use of W3C XML Schema does not cause any differences from the use of DTDs. However, declaring the datatype as short does not make the methods of DOM or SAX return integers. Their return values are of the datatype java.lang.String. For example, when the method getData() is applied to a Text node representing the content of the first quantity element, the return value is an instance of the class java.lang.String. It is not an integer. Application programmers thus have to explicitly convert strings to instances of appropriate classes. For example, we obtain an integer from a string by evaluating Int.parseInt(str), where str is the return value of the DOM or SAX method. Because the XML document has been validated against itemList.xsd, it is guaranteed that no exceptions occur during the conversion. It is planned that future versions of DOM will provide mechanisms for returning instances of specified datatypes rather than strings. It is unclear whether future versions of SAX will provide such mechanisms. Table 9.2 summarizes those built-in datatypes of W3C XML Schema that we consider particularly useful. For each datatype, we show which datatypes of Java and SQL roughly correspond to it.
Using FacetsIn the previous example, we allowed any string as a value of name and allowed any integer from ?2768 to 32767 as a value of quantity. However, we often want to specify further constraints. For example, we might want to change itemList.xsd so that permissible values of name are strings up to 5 characters and permissible values of quantity are integers greater than or equal to 0 and less than or equal to 20. In W3C XML Schema, such constraints are represented by facets. A modified version of itemList.xsd is shown in Listing 9.9. Although xsd:element elements in the previous subsection specified the attribute type, they do not have this attribute this time. Instead, they have child elements named xsd:simpleType (lines 23 and 31). Listing 9.9 Using facets, chap09/itemList-facet.xsd
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
<xsd:element name="itemList">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="item"
minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="item">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="name"/>
<xsd:element ref="quantity"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="name">
[23] <xsd:simpleType>
[24] <xsd:restriction base="xsd:token">
[25] <xsd:maxLength value="5"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="quantity">
[31] <xsd:simpleType>
[32] <xsd:restriction base="xsd:short">
[33] <xsd:maxInclusive value="20"/>
[34] <xsd:minInclusive value="0"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:schema>
An xsd:simpleType element represents an anonymous user-defined datatype. In this example, two xsd:simpleType elements occur. Both contain xsd: restriction elements (lines 24 and 32). In the description of name, the attribute base of the xsd:restriction element specifies xsd:token (line 24). This implies that this user-defined datatype is created by imposing restrictions on the built-in datatype xsd:token. The restriction is represented by the xsd:maxLength facet (line 25), which specifies that the string length is up to 5. In the description for quantity, the attribute base of the xsd:restriction element (line 32) specifies xsd:short. This implies that this user-defined data type is created by imposing restrictions on the built-in datatype xsd:short. The xsd:maxInclusive and xsd:minInclusive facets (lines 33 and 34) provide these restrictions. The former shows that permissible integers are less than or equal to 20, while the latter shows that permissible integers are greater than or equal to 0. In itemList-xsd.xml (see Listing 9.4), the second and third name elements contain a string of more than 5 characters, and the third quantity element contains an integer greater than 20. Thus, SimpleParseWithSchemaValidation reports an error as follows:
R:\samples>java chap02.SimpleParseWithSchemaValidation
chap09/itemList-facet-xsd.xml
[Error] 10:24 Datatype error: In element 'name' : Value 'eraser'
with length '6' exceeds maximum length facet of '5'..
[Error] 14:25 Datatype error: In element 'name' : Value 'stapler'
with length '7' exceeds maximum length facet of '5'..
[Error] 15:28 Datatype error: In element 'quantity' : 25 is out
of bounds:[ 0 <= X <= 20 ].
Next, we explicitly specify a list of permissible values. For example, suppose that we want to specify that the permissible values of name are pen and eraser. We do this by adding the xsd:enumeration facet (lines 25 and 26) to the declaration of name in itemList.xsd as shown in Listing 9.10. Listing 9.10 Part of itemList-enum.xsd
<xsd:element name="name">
<xsd:simpleType>
<xsd:restriction base="xsd:token">
[25] <xsd:enumeration value="pen"/>
[26] <xsd:enumeration value="eraser"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
Let us create a new document, itemList-enum-xsd.xml, by modifying itemList-xsd.xml. This document references itemList-enum.xsd and contains 20 rather than 25. Since itemList-enum-xsd.xml contains <name> stapler</name>, the following error is reported.
R:\samples>java chap02.SimpleParseWithSchemaValidation
chap09/itemList-enum-xsd.xml
[Error] 14:25 Datatype error: In element 'name' : Value 'stapler'
must be one of [pen, eraser].
Finally, we show the use of a regular expression for specifying permissible values. Suppose that we want to allow all strings ending with er. We do this by adding the xsd:pattern facet (line 25), as shown in Listing 9.11. Listing 9.11 Part of itemList-pattern.xsd
<xsd:element name="name">
<xsd:simpleType>
<xsd:restriction base="xsd:token">
[25] <xsd:pattern value=".*er"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
Let us create a new document, itemList-pattern-xsd.xml, by modifying itemList-enum-xsd.xml. This document references itemList-pattern.xsd. Since itemList-pattern-xsd.xml contains <name>pen</name>, the following error is reported.
R:\samples>java chap02.SimpleParseWithSchemaValidation
chap09/itemList-pattern-xsd.xml
[Error] 6:21 Datatype error: In element 'name' : Value 'pen'
does not match regular expression facet '.*er'..
Table 9.3 summarizes the facets of W3C XML Schema.
9.2.3 Using NamespacesAlthough the XML Namespace Recommendation was published in 1998, it did not provide namespace-aware validation. To create a DTD for documents containing namespaces, we have been forced to choose a particular namespace prefix for a namespace.[3] The choice of a particular namespace prefix conflicts with the original intention of the XML Namespace Recommendation. Furthermore, there are no standard ways to construct DTDs containing multiple namespaces.
W3C XML Schema supports namespaces. A schema written in W3C XML Schema specifies a namespace as the target. Components declared in this schema belong to that target namespace. A document containing multiple namespaces is validated against a collection of schemas, each of which specifies one of these namespaces as the target. Namespace prefixes used in documents or schemas are merely proxies for namespace names (URIs). Those in documents do not have to coincide with those used in schemas. As an example, consider the XML document shown in Listing 9.12. This document contains the namespaces http://www.example.net/foo and http://www.w3.org/1999/xhtml. Listing 9.12 A document with multiple namespaces, chap09/multiNS.xml
<?xml version="1.0" encoding="utf-8"?>
<foo xmlns="http://www.example.net/foo">
<p xmlns="http://www.w3.org/1999/xhtml"/>
<ol xmlns="http://www.w3.org/1999/xhtml">
<li>bullet 1</li>
<li>bullet 2</li>
</ol>
</foo>
Let us construct a schema for this document. The namespace for the root element foo is http://www.example.net/foo. A schema for this element is shown in Listing 9.13 Listing 9.13 A schema for the root element, chap09/foo.xsd
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
[3] targetNamespace="http://www.example.net/foo"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
[6] <xsd:import namespace="http://www.w3.org/1999/xhtml"/>
<xsd:element name="foo">
<xsd:complexType>
<xsd:choice
minOccurs="0" maxOccurs="unbounded">
[12] <xsd:element ref="xhtml:p" />
[13] <xsd:element ref="xhtml:ol" />
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
The instruction targetNamespace="http://www.example.net/foo" (line 3) shows that this schema is concerned with the namespace http://www.example.net/foo.xsd:import (line 6) shows that this schema references declarations from the namespace "http://www.w3.org/1999/xhtml/". Observe that p and ol of the namespace http://www.w3.org/1999/xhtml are referenced from the content model for foo (lines 12 and 13). The namespace for the child elements p and ol is http://www.w3.org/1999/xhtml. The element ol in turn has the child element li. A schema for these elements is shown in Listing 9.14. Listing 9.14 A schema for child elements, chap09/xhtml.xsd
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
targetNamespace="http://www.w3.org/1999/xhtml">
<xsd:element name="p" type="xsd:string"/>
<xsd:element name="ol">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="xhtml:li"
minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="li" type="xsd:string"/>
</xsd:schema>
Finally, we have to reference these schemas from the XML document. To specify foo.xsd for the namespace http://www.example.net/foo and specify xhtml.xsd for the namespace http://www.w3.org/1999/xhtml, we add the attribute schemaLocation, as shown in Listing 9.15. Again, this attribute is merely a hint. Listing 9.15 Referencing the schemas, chap09/multiNS-xsd.xml
<?xml version="1.0" encoding="utf-8"?>
<foo xmlns="http://www.example.net/foo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation= "http://www.example.net/foo
foo.xsd
http://www.w3.org/1999/xhtml
xhtml.xsd">
<p xmlns="http://www.w3.org/1999/xhtml"/>
<ol xmlns="http://www.w3.org/1999/xhtml">
<li>bullet 1</li>
<li>bullet 2</li>
</ol>
</foo>
Namespace prefixes in documents do not have to coincide with those in schemas. For example, the XML document in Listing 9.16 also conforms to the two schemas just shown. Listing 9.16 Using a different namespace prefix, chap09/multiNS-different Prefix-xsd.xml
<?xml version="1.0" encoding="utf-8"?>
<foo:foo xmlns:foo="http://www.example.net/foo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation= "http://www.example.net/foo
foo.xsd
http://www.w3.org/1999/xhtml
xhtml.xsd">
<xhtml1:p xmlns:xhtml1="http://www.w3.org/1999/xhtml"/>
<xhtml2:ol xmlns:xhtml2="http://www.w3.org/1999/xhtml">
<xhtml2:li>bullet 1</xhtml2:li>
<xhtml2:li>bullet 2</xhtml2:li>
</xhtml2:ol>
</foo:foo>
Rather than specifying the attribute schemaLocation, we can write programs that explicitly reference schemas. We only have to invoke setProperty for DOM or SAX parsers as follows:[4]
parser.setProperty( "http://apache.org/xml/properties/schema/external-schemaLocation", "http://www.example.net/foo foo.xsd" + "http://www.w3.org/1999/xhtml xhtml.xsd "); Such programs do not require the use of the attribute schemaLocation in XML documents. Even if this attribute is specified, it is simply ignored. The schemas specified by setProperty (in this example, foo.xsd and xhtml.xsd) are always used. 9.2.4 Advanced FeaturesIn this chapter, we have considered W3C XML Schema as DTD + datatypes + name spaces and only covered the relevant features of W3C XML Schema. Such restricted use of W3C XML Schema is not difficult and provides significant advantages. However, W3C XML Schema provides far more advanced features than those covered in this chapter. The following list is a very brief summary of such features. Complex typeA complex type describes permissible contents (elements and text) and attributes. Complex types are used by element declarations. Simple typeA simple type describes permissible character strings, which lexically represent values in that simple type. Simple types are used for attribute declarations or element declarations. Derivation by extensionDerivation by extension is to create a complex type from an existing type by adding child elements or attributes. Derivation by restrictionDerivation by restriction is to create a (simple or complex) type from another (simple or complex) type by imposing further restrictions. Model group definitionsA model group mimics a parameter entity describing a content model fragment. Model groups do not describe attributes. Attribute group definitionsAn attribute group mimics a parameter entity describing a group of attributes. Attribute groups do not describe child elements. WildcardsA wildcard matches elements and attributes dependent on their namespace names independently of their local names. Element substitution groupsAn element substitution group allows elements in content models to be substituted with different elements. Identity constraintsIdentity constraints are generalizations of ID/IDREF for ensuring uniqueness of elements or attribute values and using such values as keys. 9.2.5 Further InformationThe details of W3C XML Schema are described by the following W3C Recommendations. XML Schema Part 0: PrimerThis document introduces the W3C XML Schema facilities through numerous examples. XML Schema Part 1: StructuresThis document specifies the W3C XML Schema definition language, which offers facilities for describing the structure and constraining the contents of XML 1.0 documents. XML Schema Part 2: DatatypesThis document defines facilities for defining datatypes to be used in W3C XML Schema. Xerces supports W3C XML Schema, and other implementations are also available. However, some of them are beta releases and do not really conform to the W3C XML Schema Recommendation. In particular, they might not correctly support those features covered in this section. Further information, including the recommendations just listed, is available at the Web page of the XML Schema WG (http://www.w3.org/XML/Schema). |
| [ directory ] |
|