RELAX NG schema for XML Schema by Jeni Tennison. Based on XML Schema Part I: Structures Recommendation and XML Schema Part II: Datatypes. This allows any number of attributes that are not in the XML Schema namespace or are in no namespace. This is somewhat more complicated than the XML Schema anyAttribute equivalent. This allows any number of attributes that are not in the XML Schema namespace or are in no namespace, an optional id attribute of type ID, and an optional annotation element. This is used as the basis for many element content models. This gives the content model of the top level of the schema. This gives the components that can be redefined within the redefine element. They also occur at the top level of the schema. This gives the values for the various form attributes: elementFormDefault and attributeFormDefault on the schema element, and the form attributes on the element and attribute elements. qualified unqualified This gives the values that can be taken in the lists used to control derivation by extension or restriction (this is 'reduced' derivation because some derivation can involve substitution). This RELAX NG schema is stricter than the XML Schema Recommendation here, which allows the keywords 'extension' and 'restriction' to be repeated any number of times. extension restriction This specifies the possible values for attributes that control derivation. #all This is the beginning point for the schema, and defines the schema element. If a targetNamespace attribute is specified on the schema element, then the namespace attribute on the import elements that it contains are optional. If a targetNamespace attribute is not specified on the schema element, then the import elements that it contains must specify a namespace. This gives the value type for the maxOccurs attribute, which may be a non-negative number or the keyword 'unbounded'. unbounded This specifies the occurs attributes, minOccurs and maxOccurs, as they are normally used. This gives the possible content of complex types. This gives the particles that can make up a model group. This specifies the relationship between fixed and default attributes on element and attribute elements - if one is present, then the other cannot be. This is a constraint that cannot be specified using XML Schema. This specifies the relationship between the type attribute and the simpleType element child of attribute elements - if one is present, then the other cannot be, although it is possible for neither to be allowed. This describes attribute elements when used in a local context. They have an optional use attribute, possibly a fixed or default attribute, and then can either have a ref attribute (referring to a top-level attribute) or a name attribute with an optional form attribute and specifying an attribute type. optional prohibited required This describes attribute elements when used at the top level of the schema. They must have a name, may have a fixed or default attribute, and specify their type through a type attribute or child simpleType element. The name attribute of each attribute element that appears at the top level of the schema is unique. This gives the model group for specifying the attributes in a complex type, an extension or restriction. This specifies the anyAttribute wildcard. This specifies the content of a complexType element. As children, it can have a simpleContent, a complexContent or a model group. Only if it has one of the latter two, may it have a mixed attribute. This latter constraint is something that cannot be specified in XML Schema. This specifies the basic content of a complexType element. This specifies the model for a complexType element at the top level of the schema. It must have a name, which provides a unique identifier within the type symbol space. It may have abstract, block and/or final attributes. Otherwise it is the same as other complexTypes. This specifies the model for a local complexType element. This describes a restriction element within a complexContent element (i.e. one that restricts a complex type). It has a base attribute, may contain a model group and may contain attribute declarations of various sorts. This specifies the basic model for an extension element: adding a required base attribute to the model used for most components. This describes an extension element within a complexContent element (i.e. one that restricts a complex type). It may contain a model group and may contain attribute declarations of various sorts. This describes a complexContent element. It may have a mixed attribute, and either a restriction or extension element as content. This describes a restriction element that appears within a simpleContent or simpleType element (i.e. one that restricts a simple type). Its content follows the simple restriction model that is detailed below, and may include attribute declarations. This describes an extension element that appears within a simpleContent element (i.e. one that extends a simple type). Like other extensions, it has a base type, but it can only be used to add attributes. This describes a simpleContent element, whose content can either hold a restriction or extension element. This gives the possible values for block attributes on element elements, which includes substitution amongst the list of possible values. This RELAX NG schema is somewhat stricter than the XML Schema Recommendation here, only allowing each of the keywords 'extension', 'restriction' and 'substitution' to occur a maximum of once within the list. #all extension restriction substitution This describes the basic content model of an element element. It is annotated, may have a fixed or default attribute, and may have nillable and/or block attributes. Its type may be specified through a type attribute, a local simple type or a local complex type - the choice between these methods is something that cannot be indicated with XML Schema. This content is optionally followed by some identify constraints. This describes an element element that appears at the top level of the schema. On top of the basic content for an element element, it has to have a name, which is a unique identifier in the element symbol space. It may have substitutionGroup, abstract and/or final attributes. This describes an element element that appears locally, within a complexType or group element. It may have minOccurs and/or maxOccurs attributes. If it has a ref attribute, then that's all it can have. Otherwise, it must have a name and specifies its type in the same way as the basic element content model described above. It may in this case also have a form element. These constraints on local elements cannot be described within XML Schema. This describes an group element that appears at the top level of the schema. It must have a name attribute, and must have one of an all, choice or sequence element child. This describes group element that occurs locally, referring to a top-level named group. It may have occurrence attributes, and must have a ref attribute. This gives the content of a model group (not a group element) in the normal run of things. It has occurrence attributes and any number of particles within it. This gives the content of a model group (not a group element) within a named group - it differs from the above in that it doesn't have any occurrence attributes. This gives the content of an all element. It contains element elements that are similar to local element elements, but the minOccurs and maxOccurs attributes can only take values of 0 or 1. 0 1 0 1 This describes an all element that appears outside a named group (i.e. as the content of a complexType element). It has the standard model for an all element, but adds minOccurs and maxOccurs attributes which can only take certain values. 0 1 1 This describes a choice element that appears outside a named group. This describes a sequence element that appears outside a named group. This describes a wildcard element (i.e. any or anyAttribute). The namespace attribute can take a list URIs interspersed with the keywords '##targetNamespace' and/or '##local'. This RELAX NG schema is stricter than the XML Schema Recommendation here, in that it only allows the keywords to be specified once each within the list, if they're given. This model also specifies the processContents attribute. ##any ##other ##targetNamespace ##local lax skip strict This describes an any element as a wildcard. This describes an attributeGroup element as it appears at the top level of the schema. It must have a name attribute, and then contains attribute declarations. This describes an attributeGroup element as it appears within a complex type. It must have a ref attribute. This describes an include element, which must have a schemaLocation attribute. This describes a redefine element, which must have a schemaLocation attribute and can then contain any mix of annotations and redefinable components. This gives the basic model for an import element - an optional schemaLocation attribute. This describes an import element that's used when its parent schema element doesn't specify a targetNamespace. In these cases, the import element must give a namespace attribute. This describes an import element that's used when its parent schema element specifies a targetNamespace. In these cases, the namespace attribute on the import element is optional. This describes a selector element. The xpath attribute is a simplified XPath - the regular expression given here is the one from the XML Schema for XML Schema. (\.//)?(((child::)?((\i\c*:)?(\i\c*|\*)))|\.)(/(((child::)?((\i\c*:)?(\i\c*|\*)))|\.))*(\|(\.//)?(((child::)?((\i\c*:)?(\i\c*|\*)))|\.)(/(((child::)?((\i\c*:)?(\i\c*|\*)))|\.))*)* This describes a field element. The xpath attribute is a simplified XPath - the regular expression given here is the one from the XML Schema for XML Schema. (\.//)?((((child::)?((\i\c*:)?(\i\c*|\*)))|\.)/)*((((child::)?((\i\c*:)?(\i\c*|\*)))|\.)|((attribute::|@)((\i\c*:)?(\i\c*|\*))))(\|(\.//)?((((child::)?((\i\c*:)?(\i\c*|\*)))|\.)/)*((((child::)?((\i\c*:)?(\i\c*|\*)))|\.)|((attribute::|@)((\i\c*:)?(\i\c*|\*)))))* This gives the basic content for identity constraints - a name attribute that uniquely identifies the identity constraint, a selector element and one or more field elements. This gives a model group for the three identity constraint elements, used within the content of element elements. This describes a unique element. This describes a key element. This describes a keyref element. This describes a notation element. The names of notation elements are unique in the notation symbol space. The public attribute is required, and the system attribute is optional. This is designed to describe the content of the appinfo elements in the schema. At the moment this allows any mixed content without validation. Note that this is fairly complex compared to the XML Schema equivalent, which would be a single any element. This describes an appinfo element. It has an optional source attribute and can currently contain anything at all. This is designed to describe the content of the documentation elements in the schema. At the moment this allows any mixed content without validation. Note that this is fairly complex compared to the XML Schema equivalent, which would be a single any element. This describes a documentation element. It has optional source and xml:lang attributes and can currently contain anything at all. This describes an annotation element. It can have any attributes, may have an id attribute, and contains any number of documentation or appinfo elements. This gives the various types of derivation of simple types. This specifies the values of the final attribute for simple types. This RELAX NG schema for XML Schema is stricter than the XML Schema Recommendation in that it only allows the keywords 'list', 'union' and 'restriction' to appear a maximum of once within the list. #all list union restriction This gives the basic content of a simple type. This describes a simpleType element as it appears at the top level of the schema. It has to have a name attribute and may have a final attribute. This describes a simpleType element as it appears within an attribute or element. This describes the relationship between the various range facets. Only one of minExclusive and minInclusive can be present, and only one of maxExclusive and maxInclusive can be present. This is a constraint that can't easily be expressed using XML Schema. This RELAX NG schema for XML Schema is a little more restrictive than the XML Schema Recommendation in that it also forces there to be a maximum of one of each of these types of facets. This specifies optional totalDigits and fractionDigits elements. This RELAX NG schema for XML Schema is a little more restrictive than the XML Schema Recommendation in that it also forces there to be a maximum of one of each of these types of facets. This specifies optional length, minLength and maxLength elements. This RELAX NG schema for XML Schema is a little more restrictive than the XML Schema Recommendation in that it also forces there to be a maximum of one of each of these types of facets, and says that if a length element is given, then neither minLength nor maxLength should be present. This specifies zero or more enumeration or pattern elements and an optional whiteSpace element. This RELAX NG schema for XML Schema is a little more restrictive than the XML Schema Recommendation in that it also forces there to be a maximum of one whiteSpace element within the facets. Note that the whiteSpace facet is constrained to have a value of 'collapse'. This specifies the types of facets that are valid in restrictions on the built-in data types. This can only perform rudimentary checking, but should be enough in most circumstances. Note that for xs:anySimpleType and xs:string, the whiteSpace facet can take any value, for xs:normalizedString it can be 'replace' or 'collapse', and for all other built-in types it has to be 'collapse'. xs:anySimpleType xs:string xs:normalizedString xs:token xs:language xs:Name xs:NCName xs:ID xs:IDREF xs:IDREFS xs:NMTOKEN xs:NMTOKENS xs:ENTITY xs:ENTITIES xs:hexBinary xs:base64Binary xs:anyURI xs:QName xs:NOTATION xs:boolean xs:decimal xs:integer xs:nonPositiveInteger xs:nonNegativeInteger xs:positiveInteger xs:negativeInteger xs:unsignedLong xs:unsignedInt xs:unsignedShort xs:unsignedByte xs:long xs:int xs:short xs:byte xs:float xs:double xs:duration xs:dateTime xs:time xs:date xs:gYearMonth xs:gYear xs:gMonthDay xs:gMonth xs:gDay This describes a list element. It can either specify a local simple type or have a itemType attribute. This constraint cannot be expressed in XML Schema. This describes a union element. If the memberTypes attribute is missing or empty, then it must contain one or more simpleType elements; if it's present, then it can contain simpleType elements or list simple types in the memberTypes attribute. This constraint cannot be expressed in XML Schema. This is the basic content of a facet. It has an optional fixed attribute. This is the content of a facet that cannot be fixed (enumeration or pattern). It has a value attribute that can take any kind of value. This is the content of a range facet. The value must be one of the data types shown (as these are the only types of data that accept ranges). I haven't gone so far as to indicate the data type of the value attribute of a range facet according to the base type as this would be very complicated (although it would be possible in RELAX NG). This describes a minExclusive element. This describes a minInclusive element. This describes a maxExclusive element. This describes a maxInclusive element. This is the content of a numerical facet. This describes a totalDigits element. The value attribute must take a positive integer. This describes a fractionDigits element. This describes a length element. This describes a minLength element. This describes a maxLength element. This describes an enumeration element. This describes a whiteSpace element that can take any of the permitted values. preserve replace collapse This describes a whiteSpace element that can only take the values 'replace' or 'collapse'. replace collapse This describes a whiteSpace element that can only take the value 'collapse'. collapse This describes a pattern element.