Professional Documents
Culture Documents
<xs:schema
<?xml version="1.0"?>
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.put.poznan.pl"
<note>
xmlns="http://www.put.poznan.pl"
<to>Tove</to>
elementFormDefault="qualified">
<from>Jani</from>
<heading>Reminder</heading>
<xs:element name="note">
<body>Don’t forget me this weekend!</body>
<xs:complexType>
</note>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
DTD <xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<!ELEMENT note (to, from, heading, body)> <xs:element name="body" type="xs:string"/>
<!ELEMENT to (#PCDATA)> </xs:sequence>
<!ELEMENT from (#PCDATA)> </xs:complexType>
<!ELEMENT heading (#PCDATA)> </xs:element>
<!ELEMENT body (#PCDATA)>
</xs:schema>
:: based on W3Schools tutorial :: XML Schema [4/25] :: based on W3Schools tutorial :: XML Schema [5/25]
<xs:schema
Reference to DTD
XS namespace:
<!DOCTYPE note SYSTEM "http://www.put.poznan.pl/dtd/note.dtd">
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
:: based on W3Schools tutorial :: XML Schema [6/25] :: based on W3Schools tutorial :: XML Schema [7/25]
Types Attributes
:: based on W3Schools tutorial :: XML Schema [8/25] :: based on W3Schools tutorial :: XML Schema [9/25]
<xs:element name="car">
<xs:simpleType>
<xs:restriction base="xs:string">
Restrictions on XML elements are called facets <xs:enumeration value="Audi"/>
<xs:enumeration value="Honda"/>
Example: age must be between 0 and 100 <xs:enumeration value="BMW"/>
</xs:restriction>
<xs:element name="age"> </xs:simpleType>
</xs:element>
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
or define a new type carType:
<xs:maxInclusive value="100"/>
</xs:restriction> <xs:element name="car" type="carType"/>
</xs:simpleType>
<xs:simpleType name="carType">
</xs:element> <xs:restriction base="xs:string">
<xs:enumeration value="Audi"/>
<xs:enumeration value="Honda"/>
<xs:enumeration value="BMW"/>
</xs:restriction>
</xs:simpleType>
:: based on W3Schools tutorial :: XML Schema [10/25] :: based on W3Schools tutorial :: XML Schema [11/25]
Pattern Restrictions White Spaces
Example
Regular expressions, e.g.: zipcode preserve white spaces will be preserved from the document
replace all line feeds, tabs, spaces, and carriage returns will be
<xs:pattern value="[0-9]{2}-[0-9]{3}"/>
replaced with spaces
collapse all white space characters will be replaced with a single
space
:: based on W3Schools tutorial :: XML Schema [12/25] :: based on W3Schools tutorial :: XML Schema [13/25]
Examples
Length range
1. <product pid="1345"/>
<xs:simpleType> 2. <employee>
<xs:restriction base="xs:string"> <firstname>John</firstname>
<xs:minLength value="5"/> <lastname>Smith</lastname>
<xs:maxLength value="8"/> </employee>
</xs:restriction> 3. <food type="dessert">Ice cream</food>
</xs:simpleType> 4. <description>
It happened on <date lang="norwegian">03.03.99</date> ....
</description>
:: based on W3Schools tutorial :: XML Schema [14/25] :: based on W3Schools tutorial :: XML Schema [15/25]
Complex Type Definition Type Inheritance
Examples
:: based on W3Schools tutorial :: XML Schema [16/25] :: based on W3Schools tutorial :: XML Schema [17/25]
<persons>
<person>
<full_name>Tove Refsnes</full_name>
<child_name>Hege</child_name> <xs:attributeGroup name="..."> defines a new attribute group
<child_name>Stale</child_name> <xs:attributeGroup ref="..."/> references the group
</person>
</persons>
:: based on W3Schools tutorial :: XML Schema [20/25] :: based on W3Schools tutorial :: XML Schema [21/25]
:: based on W3Schools tutorial :: XML Schema [22/25] :: based on W3Schools tutorial :: XML Schema [23/25]
XML Schema Data Types Documentation
xs:string regular string
xs:normalizedString
tabs are replaced with spaces
xs:token XML processor will remove line feeds, carriage returns,
XML Schema is a W3C Recommendation
tabs, leading and trailing spaces, and multiple spaces
xs:date uses notation CCYY-MM-DD XML Schema was originally proposed by Microsoft, but became an
xs:time uses notation hh:mm:ss official W3C recommendation in May 2001.
xs:dateTime uses notation CCYY-MM-DDThh:mm.ss
XML Schema Part 1: Structures.
xs:duration uses notation PnYnMnDTnHnMnS, eg. P5Y2M10D means http://www.w3.org/TR/xmlschema-1/.
5 years, 2 months and 10 days
xs:decimal floating point numbers XML Schema Part 2: Datatypes.
http://www.w3.org/TR/xmlschema-2/.
xs:integer decimal numbers
xs:byte, xs:long, xs:short
other decimal number types
xs:boolean logical
xs:hexBinary, base64Binary, xs:anyURI
other data types
:: based on W3Schools tutorial :: XML Schema [24/25] :: based on W3Schools tutorial :: XML Schema [25/25]