Exemple : Bulletins météo (XML, DTD, RNC, XSD)

ExempleInstance XML

1
<?xml version="1.0" encoding="UTF-8"?>
2
<meteo xmlns="http://foo.bar.org/xml-schemas/mtoSchema">
3
    <obs num="PY54476VZ32">
4
        <loc>Paris-Montsouris</loc>
5
        <date>1998-10-22T15:31:05</date>
6
        <temp unit="celsius">12.3</temp>
7
        <hygro>88</hygro>
8
        <nebulo>8</nebulo>
9
        <anemo>3</anemo>
10
        <pluvio>6</pluvio>
11
    </obs>
12
    <obs num="BM655S55">
13
        <loc>Pic-du-midi-bigorre</loc>
14
        <date>1998-10-22T15:33:10</date>
15
        <temp unit="celsius">3.1</temp>
16
        <hygro>55</hygro>
17
        <nebulo>1</nebulo>
18
        <anemo>48</anemo>
19
        <pluvio>0</pluvio>
20
        <message> Anémomètre primaire HS</message>
21
    </obs>
22
</meteo>

ExempleDTD (sans typage des données)

1
<!ELEMENT meteo (obs)+>
2
<!ATTLIST meteo xmlns CDATA #FIXED 'http://foo.bar.org/xml-schemas/mtoSchema'>
3
<!ELEMENT obs (loc, date, temp?, hygro?, nebulo?, anemo?, pluvio?, message?) >
4
<!ATTLIST obs num ID #REQUIRED>
5
<!ELEMENT loc (#PCDATA)>
6
<!ELEMENT date (#PCDATA)>
7
<!ELEMENT temp (#PCDATA)>
8
<!ATTLIST temp unit (celsius | farenheight | kelvin) 'celsius' >
9
<!ELEMENT hygro (#PCDATA)>
10
<!ELEMENT nebulo (#PCDATA)>
11
<!ELEMENT anemo (#PCDATA)>
12
<!ELEMENT pluvio (#PCDATA)>
13
<!ELEMENT message (#PCDATA)>

ExempleRelaxNG compacte (avec typage grossier des données)

1
namespace rng = "http://relaxng.org/ns/structure/1.0"
2
default namespace = "http://foo.bar.org/xml-schemas/mtoSchema"
3
datatypes xsd = "http://www.w3.org/2001/XMLSchema-datatypes"
4
start= Meteo
5
Meteo = element meteo {Obs+}
6
Obs = element obs {
7
  element loc {text},
8
  element date {xsd:dateTime},
9
  element temp {TempType}?,
10
  element hygro {Pourcent} ?,
11
  element nebulo {xsd:decimal}?,
12
  element anemo {xsd:decimal}?,
13
  element pluvio {xsd:decimal}?,
14
  element message {text}?,
15
  attribute num {xsd:ID}
16
}
17
TempType = xsd:decimal, attribute unit {text}
18
Pourcent = xsd:nonNegativeInteger { maxInclusive = "100" }

ExempleW3C XML Schema (avec typage fin des données)

1
<?xml version="1.0" encoding="ISO-8859-1" ?>
2
<xs:schema targetNamespace="http://foo.bar.org/xml-schemas/mtoSchema"
3
    xmlns="http://foo.bar.org/xml-schemas/mtoSchema"
4
    xmlns:mt="http://foo.bar.org/xml-schemas/mtoSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema"
5
    elementFormDefault="qualified" attributeFormDefault="unqualified">
6
    <xs:element name="meteo" type="mt:meteoType"/>
7
    <xs:complexType name="meteoType">
8
        <xs:sequence>
9
            <xs:element name="obs" type="mt:observation" maxOccurs="unbounded"/>
10
        </xs:sequence>
11
    </xs:complexType>
12
    <xs:complexType name="observation">
13
        <xs:sequence>
14
            <xs:element name="loc" type="xs:string"/>
15
            <xs:element name="date" type="xs:dateTime"/>
16
            <xs:element name="temp" type="mt:tempType" minOccurs="0"/>
17
            <xs:element name="hygro" type="mt:pourcent" minOccurs="0"/>
18
            <xs:element name="nebulo" type="mt:octal" minOccurs="0"/>
19
            <xs:element name="anemo" type="xs:nonNegativeInteger" minOccurs="0"/>
20
            <xs:element name="pluvio" type="xs:nonNegativeInteger" minOccurs="0"/>
21
            <xs:element name="message" type="xs:string" minOccurs="0"/>
22
        </xs:sequence>
23
        <xs:attribute name="num" type="xs:ID" use="required"/>
24
    </xs:complexType>
25
    <xs:simpleType name="octal">
26
        <xs:restriction base="xs:nonNegativeInteger">
27
            <xs:maxInclusive value="8"/>
28
        </xs:restriction>
29
    </xs:simpleType>
30
    <xs:simpleType name="pourcent">
31
        <xs:restriction base="xs:nonNegativeInteger">
32
            <xs:maxInclusive value="100"/>
33
        </xs:restriction>
34
    </xs:simpleType>
35
    <xs:simpleType name="decimalT">
36
        <xs:restriction base="xs:decimal">
37
            <xs:minInclusive value="-50.0"/>
38
            <xs:maxInclusive value="+50.0"/>
39
        </xs:restriction>
40
    </xs:simpleType>
41
    <xs:complexType name="tempType">
42
        <xs:simpleContent>
43
            <xs:extension base="mt:decimalT">
44
                <xs:attribute name="unit" type="mt:tempUnit"/>
45
            </xs:extension>
46
        </xs:simpleContent>
47
    </xs:complexType>
48
    <xs:simpleType name="tempUnit">
49
        <xs:restriction base="xs:string">
50
            <xs:enumeration value="celsius"/>
51
            <xs:enumeration value="kelvin"/>
52
            <xs:enumeration value="farenheight"/>
53
        </xs:restriction>
54
    </xs:simpleType>
55
</xs:schema>
W3C XML Schema visualisé graphiquement dans l'éditeur Oxygen