21.2. Schema ElementsThe W3C XML Schema Language defines 42 elements, which naturally divide into several categories:
Elements in this section are arranged alphabetically from xs:any to xs:whiteSpace. Each element begins with a sample implementation in the following form: <xs:elementName attribute1 = "allowed attribute values" attribute2 = "allowed attribute values" > <!-- Content model --> </xs:elementName> Most attribute values can be expressed as one of the 44 XML Schema built-in simple types, such as xs:string, xs:ID, or xs:integer. Some attribute values are specified as an enumeration of the legal values in the form ( value1 | value2 | value3 | etc. ). In this case, the default value, if there is one, is given in boldface. Element content models are given in a comment in the form they might appear in an ELEMENT declaration in a DTD. For example, an xs:all element may contain a single optional xs:annotation child element followed by zero or more xs:element elements. Thus its content model is written like this: <!-- ( xs:annotation?, xs:element* ) -->
<xs:all id = "ID" maxOccurs = "1" minOccurs = "(0 | 1)"> <!-- ( xs:annotation?, xs:element* ) --> </xs:all> The xs:all element indicates that every element represented by one of its child xs:element elements must appear. However, the order of the child elements in the instance element does not matter. For example, an xs:all element can require that each FullName element have exactly one FirstName child and exactly one LastName child, but that the order of the two child elements does not matter; the first name can come first or the last name can come first. The xs:all element must be the top group in its content model (i.e., an xs:group, xs:choice, or xs:sequence cannot contain an xs:all element). The complete group represented by the xs:all element can occur either zero or one time as indicated by its minOccurs and maxOccurs attributes. By default it must occur exactly once. Furthermore, the minOccurs attribute of each of the individual xs:element elements inside the xs:all element must also be set to either 0 or 1, and the maxOccurs attribute of each of these elements must be set to 1. xs:all cannot indicate, for example, that a FullName element must contain between zero and five FirstName s and between one and three LastName s in any order.
<xs:annotation id = "ID"> <!-- ( xs:appinfo | xs:documentation )* --> </xs:annotation> The xs:annotation element is ignored by schema validators. Its purpose is to provide metainformation about the schema or schema element in which it appears. Information intended for human readers is placed in xs:documentation child elements. Information intended for software programs is placed in xs:appinfo child elements.
<xs:any id = "ID" maxOccurs = "nonNegativeInteger | unbounded" minOccurs = "nonNegativeInteger" namespace = " ##any | ##other | anyURI* ##targetNamespace? ##local? " processContents = " lax | skip | strict "> <!-- xs:annotation? --> </xs:any> The wildcard element xs:any is useful when writing schemas for languages such as XSLT that routinely include markup from multiple vocabularies that are unknown when the schema is written. It indicates that between minOccurs and maxOccurs, elements from one or more namespaces identified by the namespace attribute may appear at that position in a content model. As well as literal namespace URIs, the special value ##targetNamespace can be included in the list to indicate that any element from the schema's target namespace can be used. The special value ##local can be included in the list to indicate that elements not in any namespace can be used. Instead of the list of namespace URIs, you can use the special value ##any to indicate that all elements from any namespace or no namespace are allowed, or the special value ##other to indicate that elements from namespaces other than the schema's target namespace can be used. The processContents attribute indicates whether the elements represented by xs:any have to be declared or whether they can be completely unfamiliar to the schema. It has one of these three values:
The default value is strict.
<xs:anyAttribute id = "ID" namespace = "##any | ##other | anyURI* ##targetNamespace? ##local?" processContents = "(lax | skip | strict)" > <!-- (xs:annotation?) --> </xs:anyAttribute> The xs:anyAttribute element appears inside xs:complexType elements, where it indicates that elements of that type can have any attribute from one or more namespaces. It can also appear inside xs:attributeGroup elements, where it adds attributes from one or more namespaces as potential members of the group. The namespace attribute contains a whitespace-separated list of the namespace URIs that are allowed for this element's attributes. As well as literal namespace URIs, the special value ##targetNamespace can be included in the list to indicate that any attribute from the schema's target namespace can be used. The special value ##local can be included in the list, indicating that attributes not in any namespace (unprefixed attributes) may be used. Instead of the list of namespace URIs, you can use the special value ##any to indicate that all attributes from any namespace are allowed or the special value ##other to indicate that attributes from namespaces other than the schema's target namespace can be used. The processContents attribute indicates whether the attributes themselves have to be declared, generally as top-level attributes. It has one of these three values:
<xs:appinfo source = "anyURI"> <!-- any well-formed XML markup --> </xs:appinfo> The xs:appinfo element appears exclusively inside xs:annotation elements, where it provides machine-readable information about the schema or schema element it's documenting. It has no effect on schema validation. It can contain absolutely any XML markup: an XSLT stylesheet for the schema, a schema for the schema, a schema in a different schema language such as Schematron, or anything else you can imagine. The only restriction is that the contents must be well-formed. Alternately, instead of or in addition to including this information directly, the source attribute can point to it using a URI.
<xs:attribute default = "string" fixed = "string" form = "( qualified | unqualified ) id = "ID" name = "NCName" ref = "QName" type = "QName" use = "( optional | prohibited | required )"> <!-- ( xs:annotation?, xs:simpleType? ) --> </xs:attribute> The xs:attribute element declares an attribute. Inside an xs:complexType element it indicates that elements of that type can have an attribute with the specified name and type. Attributes
ContentsThe xs:attribute element may contain a single xs:annotation element to describe itself. This has no effect on the attribute type. In place of a type attribute, the xs:attribute element may contain a single xs:simpleType element that provides an anonymous type for the attribute derived from a base simple type.
<xs:attributeGroup id = "ID" name = "NCName" ref = "QName"> <!-- ( xs:annotation?, (xs:attribute | xs:attributeGroup)*, xs:anyAttribute? ) --> </xs:attributeGroup> The xs:attributeGroup element is used in two ways. At the top level of the schema, it has a name attribute and defines a new attribute group. The attributes in the group are indicated by the child elements of the xs:attributeGroup element. Inside an xs:complexType element or another xs:attributeGroup, it has a ref attribute but no name and adds the attributes in the referenced group to the type or group's list of attributes.
<xs:choice id = "ID" maxOccurs = "( nonNegativeInteger | unbounded )" minOccurs = "nonNegativeInteger"> <!-- ( xs:annotation?, (xs:element | xs:group | xs:choice | xs:sequence | xs:any)*) --> </xs:choice> The xs:choice element indicates that any element or group represented by one of its child elements may appear at that position in the instance document. At least minOccurs elements from the choice must appear. At most maxOccurs elements from the choice must appear. The default for both minOccurs and maxOccurs is 1.
<xs:complexContent id = "ID" mixed = "( true | false )"> <!-- ( xs:annotation?, (xs:restriction | xs:extension) ) --> </xs:complexContent> The xs:complexContent element is used inside xs:complexType elements to derive a new complex type from an existing complex type by restriction or extension. When deriving by extension, the mixed attribute must have the same value as the base type's mixed attribute. When deriving by restriction, the mixed attribute can have the value false to disallow mixed content that would be allowed in the base type. It can have the value true only if the base type allows mixed content. In other words, a derived type can disallow mixed content that's allowed in the base type, but cannot allow it if the base type doesn't already allow it.
<xs:complexType abstract = "( true | false )" block = "( #all | extension | restriction )" final = "( #all | extension | restriction )" id = "ID" mixed = "( true | false )" name = "NCName" > <!-- ( xs:annotation?, (xs:simpleContent | xs:complexContent | ((xs:group | xs:all | xs:choice | xs:sequence)?, ((xs:attribute | xs:attributeGroup)*, xs:anyAttribute?)))) --> </xs:complexType> The xs:complexType element defines a new complex type, that is, an element type that can potentially contain either child elements, attributes, or both. The valid child elements and attributes for elements of this type are specified by the contents of the xs:complexType element. The mixed attribute specifies whether the complex type is allowed to contain text interspersed with its child elements. If the xs:complexType element is a top-level element, then it has a name attribute and defines a named type. Otherwise, if the xs:complexType element appears inside an xs:element element, then it does not have a name attribute and defines an anonymous type for that element alone. If the abstract attribute has the value true, then no elements of this type can be included in instance documents--only elements of subtypes derived from this type, which are marked as elements of this type by an xsi:type attribute. If the final attribute has the value restriction, then this type cannot be subtyped by restriction. If the final attribute has the value extension, then this type cannot be subtyped by extension. If the final attribute has the value #all, then this type cannot be subtyped by either restriction or extension. The default value of the final attribute is set by the finalDefault attribute on the root xs:schema element. If the block attribute has the value extension or restriction, then instances of this type cannot be replaced in instance documents by instances of subtypes derived from this type by extension or restriction, respectively, though such subtypes may still be defined and used for other elements. If the block attribute has the value #all, then this type cannot be replaced in instance documents by instances of any subtype. The default value of the block attribute is set by the blockDefault attribute on the root xs:schema element.
<xs:documentation source = "anyURI" xml:lang = "language"> <!-- any well-formed XML markup --> </xs:documentation> The xs:documentation element appears exclusively inside xs:annotation elements where it provides human-readable information about the schema or schema element it's annotating. It has no effect on schema validation. It can contain absolutely any XML markup: XHTML, DocBook, or just plain text. The only restriction is that the contents must be well-formed. Alternately, instead of or in addition to including this information directly, the source attribute can point to it using a URI. The xml:lang attribute can be used to indicate the language in which the description is written. You could even include multiple xs:documentation elements in different languages.
<xs:element abstract = "( true | false )" block = "( #all | extension | restriction | substitution )" default = "string" final = "( #all | extension | restriction )" fixed = "string" form = "( qualified | unqualified )" id = "ID" maxOccurs = "( nonNegativeInteger | unbounded )" minOccurs = "nonNegativeInteger" name = "NCName" nillable = "( true | false )" ref = "QName" substitutionGroup = "QName" type = "QName"> <!-- ( xs:annotation?, ((xs:simpleType | xs:complexType)?, (xs:unique | xs:key | xs:keyref)*) ) --> </xs:element> The xs:element element declares an element, including its name and type. Used at the top level of the schema, it indicates a potential root element. Used inside an xs:complexType element, it indicates a potential child element of another element. Alternately, instead of specifying a name and a type, it can have a ref attribute that points to an element declaration elsewhere in the schema. Attributes
ContentsThe xs:element element may contain an optional xs:annotation. If and only if the xs:element element does not have a type attribute, then it must have either an xs:simpleType child element or an xs:complexType child element that provides an anonymous type for this element. Finally, it may have any number of xs:key, xs:keyref, and xs:unique elements to set uniqueness and identity constraints.
<xs:enumeration id = "ID" value = "anySimpleType"> <!-- (xs:annotation?) --> </xs:enumeration> The xs:enumeration facet element is used inside xs:restriction elements to derive new simple types by listing all valid values. The value attribute contains a single valid value of the type specified by the parent xs:restriction's base attribute. This xs:restriction element contains one xs:enumeration child element for each valid value.
<xs:extension base = "QName" id = "ID"> <!-- (xs:annotation?, ((xs:group | xs:all | xs:choice | xs:sequence)?, ((xs:attribute | xs:attributeGroup)*, xs:anyAttribute?))) --> </xs:extension> The xs:extension element is used inside xs:simpleContent and xs:complexContent elements to derive a new complex type that adds attributes and/or child elements not present in the base type. The base type being extended is given by the value of the base attribute. The child elements and attributes added to the base type's content model are specified by the content of the xs:extension element. An instance of such an extended type must have all the child elements required by the base type followed by all the child elements required in the xs:extension.
<xs:field id = "ID" xpath = "XPath expression"> <!-- (xs:annotation?) --> </xs:field> One or more xs:field elements are placed inside each xs:unique, xs:key, and xs:keyref element to define a value calculated by the XPath expression in the xpath attribute. The context node for this expression is set in turn to each element in the node set selected by the xs:selector element. Not all XPath expressions are allowed here. In particular, the XPath expression must limit itself to the child axis, except for the last step, which may use the attribute axis. The only node tests used are name tests (element and attribute names, the * wildcard, and the prefix:* wildcard). Abbreviated syntax must be used, and predicates are not allowed. Thus, person/name/first_name/@id is a legal XPath expression for this attribute, but person//name/@id is not. Several instances of this restricted form of XPath expression can be combined with the vertical bar so that person/name/first_name/@id | person/name/last_name/@id is also an acceptable XPath expression. Finally, the XPath expression may begin with .// so that .//name/@id is legal. However, this is the only place the descendant-or-self axis can be used. No other forms of XPath expression are allowed here.
<xs:fractionDigits fixed = "( true | false )" id = "ID" value = "nonNegativeInteger" > <!-- (xs:annotation?) --> </xs:fractionDigits> The xs:fractionDigits facet element is used when deriving from xs:decimal (and its subtypes) by restriction. It limits the number of digits allowed after the decimal point to at most the number specified by the value attribute. This sets only the maximum number of digits after the decimal point. If you want to set the minimum number of digits required, you'll have to use the xs:pattern element instead. If the fixed attribute has the value true, then types derived from this type are not allowed to override the value of fractionDigits given here.
<xs:group name = "NCName" ref = "NCName" minOccurs = "nonNegativeInteger" maxOccurs = "nonNegativeInteger | unbounded"> <!-- ( xs:annotation?, (xs:all | xs:choice | xs:sequence) ) --> </xs:group> The xs:group element can be used in two ways. As a top-level element with a name attribute, it defines a model group that can be referenced from complex types elsewhere in the schema. The content model of the group is established by a child xs:all, xs:choice, or xs:sequence element. The second use is inside a xs:complexType element. Here the xs:group element indicates that the contents of the group should appear at this point in the instance document at least as many times as indicated by the minOccurs attribute and at most as many times as indicated by the maxOccurs attribute. The default for both of these is 1. The group to be included is indicated by the ref attribute that contains the name of a top-level xs:group element found elsewhere in the schema.
<xs:import id = "ID" namespace = "anyURI" schemaLocation = "anyURI" > <!-- ( xs:annotation? ) --> </xs:import> Since each schema document has exactly one target namespace, the top-level xs:import element is needed to create schemas for documents that involve multiple namespaces. The namespace attribute contains the namespace URI for the application that the imported schema describes. If the imported schema describes elements and types in no namespace, then the namespace attribute is omitted. The optional schemaLocation attribute contains a relative or absolute URL pointing to the actual location of the schema document to import. There is no limit to import depth. Schema A can import schema B, which itself imports schema C and schema D. In such a case, schema A can use definitions and declarations from all four schemas. Even recursion (schema A imports schema B, which imports schema A) is not prohibited. Since the imported schema must describe a different target namespace than the importing schema, conflicts between definitions in the multiple schemas are normally not a problem. However, if conflicts do arise, then the schema is in error and cannot be used. There are no precedence rules for choosing between multiple conflicting definitions or declarations.
<xs:include id = "ID" schemaLocation = "anyURI"> <!-- (annotation?) --> </xs:include> The top-level xs:include element is used to divide a schema into multiple separate documents. The schemaLocation attribute contains a relative or absolute URI pointing to the schema document to include. It differs from xs:import in that all included files describe the same target namespace. There is no limit to inclusion depth. Schema A can include schema B, which itself includes schema C and schema D. In such a case, schema A can use definitions and declarations from all four documents. Even recursion (schema A includes schema B, which includes schema A) is not prohibited, though it is strongly discouraged. Instance documents would refer only to the top-level schema A in their xsi:schemaLocation or xsi:noNamespaceSchemaLocation attribute. Validation is performed after all includes are resolved. If there are any conflicts between the including schema and an included schema--for instance, one schema declares that the FullName element has a simple type, and another declares that the FullName element has a complex type--then the schema is in error and cannot be used. Most of the time schemas should be carefully managed so that each element and type is defined in exactly one schema document.
<xs:key id = "ID" name = "NCName" > <!-- (xs:annotation?, (xs:selector, xs:field+) ) --> </xs:key> Keys establish uniqueness and co-occurrence constraints among various nodes in the document. For example, you can define a key for an Employee element based on its EmployeeNumber child element and then require that each Assignment element have a team attribute whose contents are a list of employee keys. The xs:key element defines a new key. It appears only as a child of an xs:element element following the element's type. The name of the key is specified by the name attribute. The elements that have a value for this key are identified by the xs:selector child element. The value of the key for each of these nodes is given by the xs:field child element and must be unique within that set. If there is more than one xs:field child element, then the key has multiple values.
<xs:keyref id = "ID" name = "NCName" refer = "QName" > <!-- (xs:annotation?, (xs:selector, xs:field+) ) --> </xs:keyref> The xs:keyref element is placed inside xs:element elements to indicate that a certain part of those elements must match the key with the name given by the refer attribute. The value that is matched against the specified key is determined by the XPath expressions used in the xs:selector child and the xs:field child elements.
<xs:length fixed = "( true | false )" id = "ID" value = "nonNegativeInteger" > <!-- (xs:annotation?) --> </xs:length> The xs:length facet element specifies the exact number of characters in a type derived from xs:string, xs:QName, xs:language, xs:anyURI, or xs:NOTATION. When applied to a list type such as xs:ENTITIES, this facet specifies the number of items in the list. Finally, when applied to xs:hexBinary and xs:base64Binary, it specifies the number of bytes in the decoded data, rather than the number of characters in the encoded data. If the fixed attribute has the value true, then types derived from this type are not allowed to override the value of length given here.
<xs:list id = "ID" itemType = "QName" > <!-- (xs:annotation?, (xs:simpleType?) ) --> </xs:list> The xs:list element is placed inside an xs:simpleType element to derive a new list simple type from a base atomic type identified by the itemType attribute. Alternately, instead of referencing an existing simple type with itemType, a new anonymous atomic type for the list can be created by an xs:simpleType child element. In either case, the newly defined simple type is a whitespace-separated list of atomic-type instances.
<xs:maxExclusive fixed = "( true | false )" id = "ID" value = "anySimpleType" > <!-- (xs:annotation?) --> </xs:maxExclusive> The xs:maxExclusive facet element applies to all ordered types, including xs:decimal, xs:float, xs:double, xs:date, xs:duration, xs:dateTime, xs:time, xs:gDay, xs:gMonthYear, xs:gMonth, xs:gYear, and their subtypes. The value attribute contains the maximum value in a form appropriate for the type. For example, the maximum for a type derived from xs:integer might be 75; the maximum for a type derived from xs:double might be 1.61803; and the maximum for a type derived from xs:date might be 2001-09-26. All instances of this type must be strictly less than the maximum value. They may not be equal to the maximum. If the fixed attribute has the value true, then types derived from this type are not allowed to override the value of maxExclusive given here.
<xs:maxInclusive fixed = "( true | false )" id = "ID" value = "anySimpleType" > <!-- (xs:annotation?) --> </xs:maxInclusive> The xs:maxInclusive facet element applies to all ordered types, including xs:decimal, xs:float, xs:double, xs:date, xs:duration, xs:dateTime, xs:time, xs:gDay, xs:gMonthYear, xs:gMonth, xs:gYear, and their subtypes. The value attribute contains the maximum value in a form appropriate for the type. For example, the maximum for a type derived from xs:integer might be 75; the maximum for a type derived from xs:double might be 1.61803; and the maximum for a type derived from xs:date might be 2001-09-26. All instances of this type must be less than or equal to the maximum value. They may be equal to the maximum. If the fixed attribute has the value true, then types derived from this type are not allowed to override the value of maxInclusive given here.
<xs:maxLength fixed = "( true | false )" id = "ID" value = "nonNegativeInteger" > <!-- (xs:annotation?) --> </xs:maxLength> The xs:maxLength facet element specifies the maximum number of characters in a type derived from xs:string, xs:QName, xs:language, xs:anyURI, or xs:NOTATION. It can also be used to restrict xs:hexBinary and xs:base64Binary. However, in this case, it refers to the maximum number of bytes in the decoded data rather than the maximum number of characters in the encoded data. Finally, when applied to a list type such as xs:IDREFS, it describes the maximum number of items in the list. If the fixed attribute has the value true, then types derived from this type are not allowed to override the value of maxLength given here.
<xs:minExclusive fixed = "( true | false )" id = "ID" value = "anySimpleType" > <!-- (xs:annotation?) --> </xs:minExclusive> The xs:minExclusive facet element applies to all ordered types, including xs:decimal, xs:float, xs:double, xs:date, xs:duration, xs:dateTime, xs:time, xs:gDay, xs:gMonthYear, xs:gMonth, xs:gYear, and their subtypes. The value attribute contains the minimum value in a form appropriate for the type. For example, the minimum for a type derived from xs:integer might be 75; the minimum for a type derived from xs:double might be 1.61803; and the minimum for a type derived from xs:date might be 2001-09-26. All instances of this type must be strictly greater than the minimum value. They may not be equal to the minimum. If the fixed attribute has the value true, then types derived from this type are not allowed to override the value of minExclusive given here.
<xs:minInclusive fixed = "( true | false )" id = "ID" value = "anySimpleType" > <!-- (xs:annotation?) --> </xs:minInclusive> The xs:minInclusive facet element applies to all ordered types, including xs:decimal, xs:float, xs:double, xs:date, xs:duration, xs:dateTime, xs:time, xs:gDay, xs:gMonthYear, xs:gMonth, xs:gYear, and their subtypes. The value attribute contains the minimum value in a form appropriate for the type. For example, the minimum for a type derived from xs:integer might be 75; the minimum for a type derived from xs:double might be 1.61803; and the minimum for a type derived from xs:date might be 2001-09-26. All instances of this type must be greater than or equal to the minimum value. If the fixed attribute has the value true, then types derived from this type are not allowed to override the value of minInclusive given here.
<xs:minLength fixed = "( true | false )" id = "ID" value = "nonNegativeInteger" > <!-- (xs:annotation?) --> </xs:minLength> The xs:minLength facet element specifies the minimum number of characters in a type derived from xs:string, xs:QName, xs:language, xs:anyURI, or xs:NOTATION. It can also be used to restrict xs:hexBinary and xs:base64Binary. However, in this case, it refers to the minimum number of bytes in the decoded data rather than the minimum number of characters in the encoded data. Finally, when applied to a list type such as xs:IDREFS, it describes the minimum number of items in the list. If the fixed attribute has the value true, then types derived from this type are not allowed to override the value of maxLength given here.
<xs:notation id = "ID" name = "NCName" public = "PUBLIC identifier" system = "anyURI" > <!-- (xs:annotation?) --> </xs:notation> The top-level xs:notation element defines a notation. It's the schema equivalent of the DTD's <!NOTATION> declaration. Each notation has a name, a public ID, and a system ID identified by the relevant attribute on this element.
<xs:pattern id = "ID" value = "regular expression" > <!-- (xs:annotation?) --> </xs:pattern> The xs:pattern facet element is used to derive new simple types by specifying a regular expression against which values of the type are compared. It applies to all simple types. The schema regular-expression grammar is quite similar to that used in Perl 5.6 and later. (The big change from earlier versions of Perl is support for Unicode character class-based regular expressions.) Most strings and characters match themselves, but a few characters have special meanings, as summarized in Table 21-1. In this table, A and B are subexpressions; n and m are non-negative integers; a, b, c, and d are all single Unicode characters; and X is a name. Table 21-1. XML Schema regular-expression syntax
Table 21-2. Unicode character classes
<xs:redefine id = "ID" schemaLocation = "anyURI" > <!-- (annotation | (simpleType | complexType | group | attributeGroup))* --> </xs:redefine> The xs:redefine element is used much like xs:include. That is, it inserts definitions and declarations for the same target namespace from a schema document found at a URL specified by the schemaLocation attribute. However, unlike xs:include, xs:redefine can override type, model group, and attribute group definitions from the included schema. The new type and group definitions are children of the xs:redefine element. They must extend or restrict the original definition of the redefined type or group. Note, however, that xs:redefine cannot override element and attribute declarations made in the included schema.
<xs:restriction base = "QName" id = "ID"> <!-- ( xs:annotation?, ( (xs:simpleType?, ( xs:minExclusive | xs:minInclusive | xs:maxExclusive | xs:maxInclusive | xs:totalDigits | xs:fractionDigits | xs:length | xs:minLength | xs:maxLength | xs:enumeration | xs:whiteSpace | xs:pattern)*) | ( (xs:group | xs:all | xs:choice | xs:sequence)?, ((xs:attribute | xs:attributeGroup)*, xs:anyAttribute?) ) ) --> </xs:restriction> The xs:restriction element derives a new type from an existing base type identified by either a base attribute or an xs:simpleType child element. When deriving by restriction, all valid values of the derived type must also be legal values of the base type. However, the reverse is not true. The valid values of the derived type are a subset (almost always a proper subset) of the valid values of the base type. For derived simple types, the allowed values are identified by the various facet child elements of the xs:restriction element. For derived complex types, the allowed values are identified by the same elements you'd find inside an xs:complexType element--that is, zero or one group elements such as xs:all, xs:choice, or xs:sequence followed by attribute representation elements such as xs:attribute, xs:attributeGroup, and xs:anyAttribute.
<xs:schema attributeFormDefault = "( qualified | unqualified )" elementFormDefault = "( qualified | unqualified )" blockDefault = "( #all | extension | restriction | substitution ) finalDefault = "( #all | extension | restriction ) id = "ID" targetNamespace = "anyURI" version = "token" xml:lang = "language" > <!-- ( (xs:include | xs:import | xs:redefine | xs:annotation)*, (((xs:simpleType | xs:complexType | xs:group | xs:attributeGroup) | xs:element | xs:attribute | xs:notation), xs:annotation*)* ) --> </xs:schema> xs:schema is the root element of all schema documents. It contains all the top-level elements described elsewhere in this chapter. First come all the elements that somehow reference other schema documents, including xs:include, xs:import, and xs:redefine. These are followed by the various elements that define types and groups and declare elements and attributes. As usual, xs:annotation elements can be placed anywhere that is convenient. Attributes
WARNING: elementFormDefault is part of a misguided effort to make child elements and attributes equivalent. If you're using namespaces at all, just put all elements in the target namespace of the schema and set elementFormDefault to qualified.
<xs:selector id = "ID" xpath = "XPath expression" > <!-- (xs:annotation?) --> </xs:selector> A single xs:selector element is placed inside each xs:unique, xs:key, and xs:keyref element to specify the element nodes for which the key on key reference is defined. The node set is selected by an XPath expression contained in the value of the xpath attribute. The context node for this XPath expression is the element matched by the xs:element declaration in which the xs:unique, xs:key, or xs:keyref element appears. Not all XPath expressions are allowed here. In particular, the XPath expression must be an abbreviated location path that limits itself to the child axis. The only node tests used are element name, the * wildcard, and the prefix:* wildcard. Abbreviated syntax must be used; predicates are not allowed. Thus, person/name/first_name is a legal XPath expression for this attribute, but person//name and name/first_name/@id are not. Several instances of this restricted form of XPath expression can be combined with the vertical bar so that person/name/first_name | person/name/last_name is also an acceptable XPath expression. Finally, the XPath expression may begin with .// so that .//name is valid. However, this is the only place the descendant-or-self axis can be used. No other forms of XPath expression are allowed here.
<xs:sequence id = "ID" maxOccurs = "( nonNegativeInteger | unbounded)" minOccurs = "nonNegativeInteger" > <!-- ( xs:annotation?, ( xs:element | xs:group | xs:choice | xs:sequence | xs:any )* ) --> </xs:sequence> The xs:sequence element indicates that the elements represented by its child elements should appear at that position in the instance document in the order they're listed here. The sequence must repeat at least minOccurs times and at most maxOccurs times. The default for both minOccurs and maxOccurs is 1. The maxOccurs attribute can be set to unbounded to indicate that the sequence may repeat indefinitely.
<xs:simpleContent id = "ID" > <!-- (xs:annotation?, (xs:restriction | xs:extension)) --> </xs:simpleContent> The xs:simpleContent element is used inside xs:complexType elements whose content is a simple type, such as xs:string or xs:integer, rather than child elements or mixed content. This is customarily done when the only reason an element has a complex type instead of a simple type is for the purpose of attributes.
<xs:simpleType final = "( #all | list | union | restriction )" id = "ID" name = "NCName" > <!-- (xs:annotation?, (xs:restriction | xs:list | xs:union)) --> </xs:simpleType> The xs:simpleType element defines a new simple type for elements and attributes. A simple type is composed purely of text but no child elements--#PCDATA, in DTD parlance. A top-level xs:simpleType element has a name given in the name attribute by which it can be referred to from the type attribute of xs:element and xs:attribute elements. Alternately, an xs:element or xs:attribute element can have an xs:simpleType child without a name attribute that defines an anonymous type for that element or attribute. New types are derived from existing types in one of three ways: by restricting the range of a base type using an xs:restriction child element, by combining multiple base types with an xs:union child element, or by allowing multiple values of a base type separated by whitespace with an xs:list child element. The final attribute can be used to prevent a simple type from being subtyped. If final contains the value list, the type cannot be extended by listing. If final contains the value restriction, the type cannot be extended by restriction. If final contains the value union, the type cannot become a member of a union. These three values can be combined in a whitespace-separated list. For instance, final="list union" prevents derivation by list and union but not by restriction. If final has the value #all, the type cannot be used as a base type in any way.
<xs:totalDigits fixed = "( true | false )" id = "ID" value = "positiveInteger" > <!-- (xs:annotation?) --> </xs:totalDigits> The xs:totalDigits facet element is used when deriving from xs:decimal elements and its descendants (xs:integer, xs:long, xs:nonNegativeInteger, xs:unsignedLong, etc.) by restriction. It specifies the maximum number of digits allowed in the number, including both the integer and fractional parts, but not counting the decimal point or the sign. This only sets the maximum number of digits. If you want to specify a minimum number of digits, use the xs:pattern element instead. If the fixed attribute has the value true, then types derived from this type are not allowed to override the value of fractionDigits given here.
<xs:union id = "ID" memberTypes = "List of QName" > <!-- (xs:annotation?, (xs:simpleType*)) --> </xs:union> The xs:union element is placed inside an xs:simpleType to indicate that an element or attribute can contain any one of multiple types. For example, it can say that an element can contain either an xs:integer or an xs:token. The names of the types that participate in the union are listed in the memberTypes attribute separated by whitespace. Furthermore, the types defined in the xs:simpleType children of the xs:union are also members of the union.
<xs:unique id = "ID" name = "NCName" > <!-- (xs:annotation?, xs:selector, xs:field+ ) --> </xs:unique> The xs:unique element requires that a specified subset of elements and/or attributes in the instance document have unique values calculated from each of those elements/attributes. This is similar to the constraint imposed by declaring an attribute to have type xs:ID, but much more flexible. The xs:selector child element uses XPath to specify the subset of nodes from the instance document over which uniqueness is calculated. The xs:field children use XPath expressions to specify what properties of those nodes must be unique within the subset.
<xs:whiteSpace fixed = "( true | false )" id = "ID" value = "(collapse | preserve | replace)" > <!-- (xs:annotation?) --> </xs:whiteSpace> The xs:whiteSpace facet element is unusual in that it does not constrain values. Instead, it tells the validator how it should normalize whitespace before validating the value against other facets. The value attribute has one of three values:
Copyright © 2002 O'Reilly & Associates. All rights reserved. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|