PB138 — XML Schema Basic sources of information • XML Schema Specification • Using W3C XML Schema Tutorial brief • XML Schema Tutorial at W3Schools • More comprehensive complete tutorial at xfront.com • How to add XML Schema support to Netbeans IDE available at Geertjan’s Blog • Try this XML Schema online validator or • Similar but more general Validome validator (not only XML schema) alternativelly available in web archive. Motivation Stronger tool for XML data model specification than DTD, it allows: • Separate type (e.g. element type) from its occurrence (i.e. element with particular name) • More primitive data types. • Allows to use namespaces. • Allows to specify content model (elements) more accurate way. • Allows new type inheritance. • Allows modular schema design and schema reuse. • XML Schema has an XML syntax. XML Schema Definition Header   .../... Assignment of type to element with the given name 1   short type reference: Simple Type Definition • Does not contain any child elements. Can be used like either element or attribute type. • Possible to define using an existing type restriction   ... Simple type definition (Example 1) Content length restriction   Simple type definition (Example 2) Content restriction using a regular expression   2 Simple types — union • Approximately correspond to C "union" concept. • Result is a simple type. • Base type and values enumeration can be merged. Simple types — union                               Simple types - values enumeration • Type can be defined as a values list separated by white-spaces. • The number of elements list limitation can used as a next derivation type. Simple types - values enumeration           3 Complex type definition     ...       and can be used instead of sequence. Complex type definition — element groups • The group element can be used to define complex type. • Group of elements:     ...   and can be used instead of sequence. Complex type definition — attribute groups • Attribute group:       ...   • The mandatory occurrence may be specified (use="required"). Groups usage • Example of elements/attributes groups use: 4               Compositor sequence • Defines occurrence of elements in the predefined order.         .../...     .../...     Compositor sequence • sequence is a content model that allows occurrence of the defined sequence of child elements. • xs prefix is (as usually) bound to the NS with URL http://www.w3.org/2001/XMLSchema • Either or can be used instead of . Compositor choice • Defines the occurrence of only one of the specified child elements or groups of elements.         .../...     .../...     5 Compositor all • Defines occurrence of child elements without definition of their order. • May appear on the definition top level only. • The cardinality of child elements can be one at most. Compositor all                 Element simple content                   Mixed element content • The text content (textual child nodes) can not be validated. • The child elements can be validated. 6                   Further options • Possibility to specify integrity limitations: ◦ value is unique — xs:unique ◦ value is a key — xs:key ◦ value is a key reference — xs:keyref Schema annotation • Annotation is a human-readable note (comment) of a schema or its part. • It may contain the processing information, see example xs:appinfo as well. • Next content is not specified (limited), see example (bind, class, …) Schema annotation     Top level element.   Element racine.             Schema definition reuse • Direct:   7 • With redefinition:           Abstract and final types abstract Type can not be instantiated. • Can be used for inheritance derivation only. final Type can not be extended/derived by inheritance. Namespaces in XML Schema   .../... Unspecified elements and attributes • XML Schema allows to use some elements that are not known prior to its use.       Use xs:anyAttribute for attributes. 8 Schema definition reference 9