[http://creativecommons.org/licenses/by/3.0/]
This work is licensed under a CC
Attribution 3.0 Unported License [http://creativecommons.org/licenses/by/3.0/]
XSD allows greater flexibility in defining constraints on intra-document references than the ID/IDREF construct of DTDs. XSD's Identity Constraints are scoped, typed, and can be used for elements or attributes. They are more powerful that the DTD's limited ID/IDREF mechanism, but still lack sufficient generality to support a really wide set of model constraints to be expressed. XSD complex types can be derived by restriction or extension. Complex type restriction defines the restricted type to be a more restricted version of the base type. Complex type extension make it possible to extend the base type by either adding attributes or contents (only by appending new content to the content model). Complex type derivation allows XSD to express type hierarchies of complex types, which can be aligned with more or less specialized code for processing instances of these types.
typesare always anonymous (they cannot be reused)
<!ELEMENT person (name, address) >
<!ATTLIST person id ID #REQUIRED >
<xs:complexType name="mixedType" mixed="true"> <xs:choice maxOccurs="unbounded" minOccurs="0"> <xs:element ref="b"/> <xs:element name="i" type="xs:string"/> <xs:element name="u" type="xs:string"/> </xs:choice> <xs:attribute ref="class"/> </xs:complexType> <xs:element name="b" type="xs:string"/>
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="billingAddress" type="addressType"/> <xs:element name="shippingAddress" type="addressType"/> <xs:complexType name="addressType"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="street" type="xs:string"/> <xs:element name="city" type="xs:string"/> <xs:element name="state" type="xs:string" minOccurs="0"/> <xs:element name="zip" type="xs:decimal"/> </xs:sequence> <xs:attribute name="country" type="xs:NMTOKEN"/> </xs:complexType> </xs:schema>
ATTLIST
, not in the ELEMENT
definition<!ELEMENT person (name, address) >
<!ATTLIST person id ID #REQUIRED >
<!ATTLIST person id ID #REQUIRED >
ATTLIST
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="p" type="mixedType"/> <xs:complexType name="mixedType" mixed="true"> <xs:choice maxOccurs="unbounded" minOccurs="0"> <xs:element ref="b"/> <xs:element name="i" type="xs:string"/> <xs:element name="u" type="xs:string"/> </xs:choice> <xs:attribute ref="class"/> </xs:complexType> <xs:element name="b" type="xs:string"/> <xs:attribute name="class"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="comment"/> <xs:enumeration value="warning"/> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com/">
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Multicolumn Layout in HTML</title> <style type="text/css">
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com/" elementFormDefault="qualified" attributeFormDefault="unqualified">
ID
s must be XML names (no numbers allowed)2
≟ +00002
should be evaluated based on the type (string or decimal?)US
use="optional"
use="required"
or use="prohibited"
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:complexType name="addressType"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="street" type="xs:string"/> <xs:element name="city" type="xs:string" minOccurs="0"/> <xs:choice> <xs:element name="state" type="xs:string"/> <xs:element name="canton" type="xs:string"/> </xs:choice> <xs:element name="zip" type="xs:decimal"/> </xs:sequence> <xs:attribute name="country" type="xs:NMTOKEN"/> <xs:attribute name="territory" type="xs:string" use="optional"/> </xs:complexType> <xs:complexType name="USaddressType"> <xs:complexContent> <xs:restriction base="addressType"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="street" type="xs:string"/> <xs:element name="city" type="xs:string"/> <xs:choice> <xs:element name="state" type="xs:string"/> </xs:choice> <xs:element name="zip" type="zipType"/> </xs:sequence> <xs:attribute name="country" type="xs:NMTOKEN"/> <xs:attribute name="territory" type="xs:string" use="prohibited"/> </xs:restriction> </xs:complexContent> </xs:complexType> <xs:simpleType name="zipType"> <xs:restriction base="xs:decimal"> <xs:totalDigits value="5"/> </xs:restriction> </xs:simpleType> </xs:schema>
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:complexType name="addressType"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="street" type="xs:string"/> <xs:element name="city" type="xs:string" minOccurs="0"/> <xs:choice> <xs:element name="state" type="xs:string"/> <xs:element name="canton" type="xs:string"/> </xs:choice> <xs:element name="zip" type="xs:decimal"/> </xs:sequence> <xs:attribute name="country" type="xs:NMTOKEN"/> <xs:attribute name="territory" type="xs:string" use="optional"/> </xs:complexType> <xs:complexType name="businessAddressType"> <xs:complexContent> <xs:extension base="addressType"> <xs:sequence> <xs:element name="company" type="xs:string"/> <xs:element name="position" type="xs:string" minOccurs="0"/> </xs:sequence> <xs:attribute name="relationship" type="xs:NMTOKEN"/> </xs:extension> </xs:complexContent> </xs:complexType> </xs:schema>
handling extensionscan be as simple as skipping them