<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> .../... </xs:schema>
Stronger tool for XML data model specification than DTD, it allows:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> .../... </xs:schema>
<xs:element name="element_name"> <!-- here comes the type definition -- placed either right here (so called "local") or as a referenced one (so called "global") --> </xs:element>
<xs:simpleType name="TypeName"> <xs:restriction base="BaseTypeName"> ... </xs:restriction> </xs:simpleType>
Content length restriction
<xs:simpleType name="nameType"> <xs:restriction base="xs:string"> <xs:maxLength value="32"/> </xs:restriction> </xs:simpleType>
Content restriction using a regular expression
<xs:simpleType name="isbnType"> <xs:restriction base="xs:string"> <xs:pattern value="[0-9]{10}"/> </xs:restriction> </xs:simpleType>
<xs:simpleType name="isbnType"> <xs:union> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="[0-9]{10}"/> </xs:restriction> </xs:simpleType> <xs:simpleType> <xs:restriction base="xs:NMTOKEN"> <xs:enumeration value="TBD"/> <xs:enumeration value="NA"/> </xs:restriction> </xs:simpleType> </xs:union> </xs:simpleType>
<xs:simpleType name="isbnTypes"> <xs:list itemType="isbnType"/> </xs:simpleType> <xs:simpleType name="isbnTypes10"> <xs:restriction base="isbnTypes"> <xs:minLength value="1"/> <xs:maxLength value="10"/> </xs:restriction> </xs:simpleType>
<xs:complexType name="TypeName"> <xs:sequence> <xs:element ...> ... <xs:attribute ...> </xs:element> </xs:sequence> </xs:complexType>
<xs:choice>
and <xs:all>
can be used instead of sequence.
<xs:group name="GroupName"> <xs:sequence> <xs:element ... /> ... </xs:sequence> </xs:group>
<xs:choice>
and <xs:all>
can be used instead of sequence.
<xs:attributeGroup name="AttributesGroupName"> <xs:attribute ... use="required"/> ... </xs:attributeGroup>
use="required"
).
<xs:complexType name="bookType"> <xs:sequence> <xs:group ref="mainBookElements"/> <xs:element name="character" type="characterType" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> <xs:attributeGroup ref="bookAttributes"/> </xs:complexType>
<xs:element name="element_name"> <xs:complexType> <xs:sequence> .../... </xs:sequence> .../... </xs:complexType> </xs:element>
xs
prefix is (as usually) bound to the NS with URL http://www.w3.org/2001/XMLSchema
<xs:choice>
or <xs:all>
can be used instead of <xs:sequence>
.
<xs:element name="element_name"> <xs:complexType> <xs:choice> .../... </xs:choice> .../... </xs:complexType> </xs:element>
<xs:complexType name="bookType"> <xs:all> <xs:element name="title" type="xs:string"/> <xs:element name="author" type="xs:string"/> <xs:element name="character"type="characterType" minOccurs="0" maxOccurs="1"/> </xs:all> <xs:attribute name="isbn" type="isbnType" use="required"/> </xs:complexType>
<xs:element name="book"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute name="isbn" type="isbnType"/> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element>
<xs:element name="book"> <xs:complexType mixed="true"> <xs:all> <xs:element name="title" type="xs:string"/> <xs:element name="author" type="xs:string"/> </xs:all> <xs:attribute name="isbn" type="xs:string"/> </xs:complexType> </xs:element>
xs:unique
xs:key
xs:keyref
<xs:annotation> <xs:documentation xml:lang="en">Top level element.</xs:documentation> <xs:documentation xml:lang="fr">Element racine.</xs:documentation> <xs:appinfo source="http://example.com/foo/"> <bind xmlns="http://example.com/bar/"> <class name="Book"/> </bind> </xs:appinfo> </xs:annotation>
<xs:include schemaLocation="character.xsd"/>
<xs:redefine schemaLocation="character12.xsd"> <xs:simpleType name="nameType"> <xs:restriction base="xs:string"> <xs:maxLength value="40"/> </xs:restriction> </xs:simpleType> </xs:redefine>
abstract
Type can not be instantiated.
final
Type can not be extended/derived by inheritance.
<xs:schema targetNamespace="http://example.org/ns/books/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:bk="http://example.org/ns/books/" elementFormDefault="qualified" attributeFormDefault="unqualified"> .../... </xs:schema>
<xs:complexType name="descType" mixed="true"> <xs:sequence> <xs:any namespace="http://www.w3.org/1999/xhtml" processContents="skip" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType>
Use xs:anyAttribute
for attributes.
<book isbn="0836217462" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:library.xsd">
<book isbn="0836217462" xmlns="http://example.org/ns/books/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="file:library.xsd">