XML Schema is the most popular schema language for XML today. It has been introduced to overcome some of the commonly observed limitations of DTDs, most notably the lack of typing. Simple Types describe content which is not structured by XML markup, which means it describes attribute values and element content. Simple types can be defined by deriving new types from existing types by using type restriction. Complex Types describe element content if this content is using attributes and/or element content other than only character data. Using XML Schema's type concepts, it is easier to represent model-level information in a schema, because type hierarchies can represent model-level specializations.
XML Schema is a language for describing an XML schema.
An XML schema can be defined using XML Schema.
I would like to use XML Schema for my XML schema.
getting into people's heads
DTD | XML Schema | |
---|---|---|
Concepts | some conceptual model (formal/informal) | |
Types | ID/IDREF and (#P)CDATA | Hierarchy of Simple and Complex Types |
Markup Constructs | Element Type Declarations <!ELEMENT order ... |
Element Definitions <xs:element name="order"> ... |
Instances (Documents) | <order date=""> [ order content ] </order> |
<phone>+1-510-6432253</phone>
)undefined
)<xs:element name="home" type="phoneType"/> <xs:element name="office" type="phoneType"/> <xs:simpleType name="phoneType"> <xs:restriction base="xs:string"> <xs:maxLength value="30"/> </xs:restriction> </xs:simpleType>
<xs:element name="business"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:maxLength value="30"/> </xs:restriction> </xs:simpleType> </xs:element>
by definition
anySimpleType
minLength
and maxLength
)length, minLength, maxLength, pattern, enumeration, whiteSpace, maxInclusive, maxExclusive, minExclusive, minInclusive, totalDigits, fractionDigits
maxLength
)string |
length, minLength, maxLength, pattern, enumeration, whiteSpace |
---|---|
boolean |
pattern, whiteSpace |
float |
pattern, enumeration, whiteSpace, maxInclusive, maxExclusive, minInclusive, minExclusive |
double |
pattern, enumeration, whiteSpace, maxInclusive, maxExclusive, minInclusive, minExclusive |
decimal |
totalDigits, fractionDigits, pattern, whiteSpace, enumeration, maxInclusive, maxExclusive, minInclusive, minExclusive |
duration |
pattern, enumeration, whiteSpace, maxInclusive, maxExclusive, minInclusive, minExclusive |
dateTime |
pattern, enumeration, whiteSpace, maxInclusive, maxExclusive, minInclusive, minExclusive |
time |
pattern, enumeration, whiteSpace, maxInclusive, maxExclusive, minInclusive, minExclusive |
date |
pattern, enumeration, whiteSpace, maxInclusive, maxExclusive, minInclusive, minExclusive |
gYearMonth |
pattern, enumeration, whiteSpace, maxInclusive, maxExclusive, minInclusive, minExclusive |
gYear |
pattern, enumeration, whiteSpace, maxInclusive, maxExclusive, minInclusive, minExclusive |
gMonthDay |
pattern, enumeration, whiteSpace, maxInclusive, maxExclusive, minInclusive, minExclusive |
gDay |
pattern, enumeration, whiteSpace, maxInclusive, maxExclusive, minInclusive, minExclusive |
gMonth |
pattern, enumeration, whiteSpace, maxInclusive, maxExclusive, minInclusive, minExclusive |
hexBinary |
length, minLength, maxLength, pattern, enumeration, whiteSpace |
base64Binary |
length, minLength, maxLength, pattern, enumeration, whiteSpace |
anyURI |
length, minLength, maxLength, pattern, enumeration, whiteSpace |
QName |
length, minLength, maxLength, pattern, enumeration, whiteSpace |
NOTATION |
length, minLength, maxLength, pattern, enumeration, whiteSpace |
de
, de-CH
, and other tags([a-zA-Z]{2}|[iI]-[a-zA-Z]+|[xX]-[a-zA-Z]{1,8})(-[a-zA-Z]{1,8})*
pattern
, the lexical space can also be restrictedSimple Types | Complex Types | |||
---|---|---|---|---|
Simple Content | Complex Content | |||
Element Only | Mixed | Empty |
,
) and alternatives (|
)#PCDATA
into the content model( #PCDATA | a | b )*
mixed
attribute on the type marks the type as being mixed<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>
EMPTY
is usedtypesare 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"/>
ATTLIST
, not in the ELEMENT
definition<!ELEMENT person (name, address) >
<!ATTLIST person id ID #REQUIRED >
<!ATTLIST person id ID #REQUIRED >
ATTLIST
<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"
handling extensionscan be as simple as skipping them