|
|
This work is licensed under a Creative Commons |
In most scenarios today, structured data is exchanged using XML. For non-trivial data structures, it is important to have a schema for the data structures, so that users know what to expect and/or what to generate. XML Schema is the most popular language for XML schemas today. XML Schema has many powerful and complex features, which means that any problem can be solved in many different ways in XML Schema. This lecture describes some guidelines for writing well-designed, open, extensible, and well-documented XML schemas.
| 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
anySimpleTypeminLength and maxLength)length, minLength, maxLength, pattern, enumeration, whiteSpace, maxInclusive, maxExclusive, minExclusive, minInclusive, totalDigits, fractionDigitsmaxLength)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 restricted| Simple 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 usedopen content
Design for Changeis very important for data modeling