XML Schema Definition Language: Unterschied zwischen den Versionen
Michi (Diskussion | Beiträge) K (hat "XML Schema Definition Langauge" nach "XML Schema Definition Language" verschoben) |
Michi (Diskussion | Beiträge) |
||
(13 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
Zeile 1: | Zeile 1: | ||
Die <b>XML-Schema Definition Language / XSD</b> ist ein Standard des W3C. | Die <b>XML-Schema Definition Language / XSD</b> ist ein Standard des W3C. | ||
+ | |||
+ | == Verwendung == | ||
+ | |||
+ | Definition eines Elements "kontakt" vom Typ "string" in der XSD-Datei "kontakt.xsd". | ||
+ | |||
+ | {| class=wiki width=100% | ||
+ | | width=50% | | ||
+ | <source lang=xml enclose=div> | ||
+ | <?xml version="1.0" encoding="UTF-8"?> | ||
+ | <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> | ||
+ | <xs:element name="kontakt" type="xs:string" /> | ||
+ | </xs:schema> | ||
+ | </source> | ||
+ | |} | ||
+ | |||
+ | Eine Beispieldatei "kontakt.xml" dazu: | ||
+ | |||
+ | {| class=wiki width=100% | ||
+ | | width=50% | | ||
+ | <source lang=xml enclose=div> | ||
+ | <?xml version="1.0" encoding="UTF-8"?> | ||
+ | <kontakt xsi:noNamespaceSchemaLocation="kontakt.xsd" | ||
+ | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" /> | ||
+ | </source> | ||
+ | |} | ||
+ | |||
+ | Eine weitere Beispieldatei "kontakt.xsd": | ||
+ | |||
+ | {| class=wiki width=100% | ||
+ | | width=50% | | ||
+ | <source lang=xml enclose=div> | ||
+ | <?xml version="1.0" encoding="UTF-8"?> | ||
+ | <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> | ||
+ | <xs:element name="kontakt"> | ||
+ | <xs:complexType> | ||
+ | <xs:sequence> | ||
+ | <xs:element name="Vorname" type="xs:string" minOccurs="0" maxOccurs="3"/> | ||
+ | <xs:element name="Nachname" type="xs:string"/> | ||
+ | </xs:sequence> | ||
+ | </xs:complexType> | ||
+ | </element> | ||
+ | </xs:schema> | ||
+ | </source> | ||
+ | |} | ||
+ | |||
+ | Die passende Datei "kontakt.xml" dazu. | ||
+ | |||
+ | {| class=wiki width=100% | ||
+ | | width=50% | | ||
+ | <source lang=xml enclose=div> | ||
+ | <?xml version="1.0" encoding="UTF-8"?> | ||
+ | <kontakt xsi:noNamespaceSchemaLocation="kontakt.xsd" | ||
+ | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
+ | <vorname>Matthias</vorname> | ||
+ | <nachname>Born</nachname> | ||
+ | </kontakt> | ||
+ | </source> | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class=wiki width=100% | ||
+ | | width=50% | | ||
+ | <source lang=xml enclose=div> | ||
+ | <?xml version="1.0" encoding="UTF-8"?> | ||
+ | <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> | ||
+ | <xs:element name="kontakt"> | ||
+ | <xs:complexType> | ||
+ | <xs:sequence> | ||
+ | <xs:element name="vorname" type="xs:string" minOccurs="0" maxOccurs="3"/> | ||
+ | <xs:element name="nachname" type="xs:string"/> | ||
+ | <xs:element name="adresse"> | ||
+ | <xs:complexType> | ||
+ | <xs:sequence> | ||
+ | <xs:element name="strasse" type="xs:string"/> | ||
+ | <xs:element name="plz"> | ||
+ | <xs:simpleType> | ||
+ | <xs:restriction base="xs:string"> | ||
+ | <xs:pattern value="[0-9][0-9][0-9][0-9][0-9]"/> | ||
+ | </xs:restriction> | ||
+ | </xs:simpleType> | ||
+ | </xs:element> | ||
+ | <xs:element name="stadt" type="xs:string"/> | ||
+ | </xs:sequence> | ||
+ | </xs:complexType> | ||
+ | </xs:element> | ||
+ | </xs:sequence> | ||
+ | </xs:complexType> | ||
+ | </xs:element> | ||
+ | </xs:schema> | ||
+ | </source> | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class=wiki width=100% | ||
+ | | width=50% | | ||
+ | <source lang=xml enclose=div> | ||
+ | <?xml version="1.0" encoding="UTF-8"?> | ||
+ | <kontakt xsi:noNamespaceSchemaLocation="kontakt.xsd" | ||
+ | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
+ | <vorname>Matthias</vorname> | ||
+ | <nachname>Born</nachname> | ||
+ | <adresse> | ||
+ | <strasse>Finkenweg</strasse> | ||
+ | <plz>45000</plz> | ||
+ | <stadt>Berlin</stadt> | ||
+ | </adresse> | ||
+ | </kontakt> | ||
+ | </source> | ||
+ | |} | ||
+ | |||
+ | Erweiterung durch Element "adressbuch". | ||
+ | |||
+ | {| class=wiki width=100% | ||
+ | | width=50% | | ||
+ | <source lang=xml enclose=div> | ||
+ | <?xml version="1.0" encoding="UTF-8"?> | ||
+ | <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> | ||
+ | <xs:element name="adressbuch"> | ||
+ | <xs:complexType> | ||
+ | <xs:sequence> | ||
+ | <xs:element ref="kontakt" maxOccurs="unbounded"/> | ||
+ | </xs:sequence> | ||
+ | </xs:complexType> | ||
+ | </xs:element> | ||
+ | <!-- Kommentar --> | ||
+ | <xs:element name="kontakt"> | ||
+ | <xs:complexType> | ||
+ | <xs:sequence> | ||
+ | <xs:element name="vorname" type="xs:string" minOccurs="0" maxOccurs="3"/> | ||
+ | <xs:element name="nachname" type="xs:string"/> | ||
+ | <xs:element name="adresse"> | ||
+ | <xs:complexType> | ||
+ | <xs:sequence> | ||
+ | <xs:element name="strasse" type="xs:string"/> | ||
+ | <xs:element name="plz"> | ||
+ | <xs:simpleType> | ||
+ | <xs:restriction base="xs:string"> | ||
+ | <xs:pattern value="[0-9][0-9][0-9][0-9][0-9]"/> | ||
+ | </xs:restriction> | ||
+ | </xs:simpleType> | ||
+ | </xs:element> | ||
+ | <xs:element name="stadt" type="xs:string"/> | ||
+ | </xs:sequence> | ||
+ | </xs:complexType> | ||
+ | </xs:element> | ||
+ | </xs:sequence> | ||
+ | </xs:complexType> | ||
+ | </xs:element> | ||
+ | </xs:schema> | ||
+ | </source> | ||
+ | |} | ||
+ | |||
+ | Zusätzliches Attribut mit lokal definiertem "simpleType". | ||
+ | |||
+ | {| class=wiki width=100% | ||
+ | | width=50% | | ||
+ | <source lang=xml enclose=div> | ||
+ | <?xml version="1.0" encoding="UTF-8"?> | ||
+ | <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> | ||
+ | <xs:element name="adressbuch"> | ||
+ | <xs:complexType> | ||
+ | <xs:sequence> | ||
+ | <xs:element ref="kontakt" maxOccurs="unbounded"/> | ||
+ | </xs:sequence> | ||
+ | </xs:complexType> | ||
+ | </xs:element> | ||
+ | <!-- Kommentar --> | ||
+ | <xs:element name="kontakt"> | ||
+ | <xs:complexType> | ||
+ | <xs:sequence> | ||
+ | <xs:element name="vorname" type="xs:string" minOccurs="0" maxOccurs="3"/> | ||
+ | <xs:element name="nachname" type="xs:string"/> | ||
+ | <xs:element name="adresse" maxOccurs="3"> | ||
+ | <xs:complexType> | ||
+ | <xs:sequence> | ||
+ | <xs:attribute name="art" use="required"> | ||
+ | <xs:simpleType> | ||
+ | <xs:restriction base="xsd:string"> | ||
+ | <xs:enumeration value="geschäftlich"/> | ||
+ | <xs:enumeration value="privat"/> | ||
+ | </xs:restriction> | ||
+ | </xs:simpleType> | ||
+ | </xs:attribute> | ||
+ | <xs:element name="strasse" type="xs:string"/> | ||
+ | <xs:element name="plz"> | ||
+ | <xs:simpleType> | ||
+ | <xs:restriction base="xs:string"> | ||
+ | <xs:pattern value="[0-9][0-9][0-9][0-9][0-9]"/> | ||
+ | </xs:restriction> | ||
+ | </xs:simpleType> | ||
+ | </xs:element> | ||
+ | <xs:element name="stadt" type="xs:string"/> | ||
+ | </xs:sequence> | ||
+ | </xs:complexType> | ||
+ | </xs:element> | ||
+ | </xs:sequence> | ||
+ | </xs:complexType> | ||
+ | </xs:element> | ||
+ | </xs:schema> | ||
+ | </source> | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class=wiki width=100% | ||
+ | | width=50% | | ||
+ | <source lang=xml enclose=div> | ||
+ | |||
+ | </source> | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class=wiki width=100% | ||
+ | | width=50% | | ||
+ | <source lang=xml enclose=div> | ||
+ | |||
+ | </source> | ||
+ | |} | ||
+ | |||
{{cat|XML}} | {{cat|XML}} |
Aktuelle Version vom 1. März 2010, 17:00 Uhr
Die XML-Schema Definition Language / XSD ist ein Standard des W3C.
Verwendung
Definition eines Elements "kontakt" vom Typ "string" in der XSD-Datei "kontakt.xsd".
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="kontakt" type="xs:string" />
</xs:schema>
|
Eine Beispieldatei "kontakt.xml" dazu:
<?xml version="1.0" encoding="UTF-8"?>
<kontakt xsi:noNamespaceSchemaLocation="kontakt.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
|
Eine weitere Beispieldatei "kontakt.xsd":
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="kontakt">
<xs:complexType>
<xs:sequence>
<xs:element name="Vorname" type="xs:string" minOccurs="0" maxOccurs="3"/>
<xs:element name="Nachname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</element>
</xs:schema>
|
Die passende Datei "kontakt.xml" dazu.
<?xml version="1.0" encoding="UTF-8"?>
<kontakt xsi:noNamespaceSchemaLocation="kontakt.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<vorname>Matthias</vorname>
<nachname>Born</nachname>
</kontakt>
|
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="kontakt">
<xs:complexType>
<xs:sequence>
<xs:element name="vorname" type="xs:string" minOccurs="0" maxOccurs="3"/>
<xs:element name="nachname" type="xs:string"/>
<xs:element name="adresse">
<xs:complexType>
<xs:sequence>
<xs:element name="strasse" type="xs:string"/>
<xs:element name="plz">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9][0-9][0-9][0-9][0-9]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="stadt" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
|
<?xml version="1.0" encoding="UTF-8"?>
<kontakt xsi:noNamespaceSchemaLocation="kontakt.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<vorname>Matthias</vorname>
<nachname>Born</nachname>
<adresse>
<strasse>Finkenweg</strasse>
<plz>45000</plz>
<stadt>Berlin</stadt>
</adresse>
</kontakt>
|
Erweiterung durch Element "adressbuch".
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="adressbuch">
<xs:complexType>
<xs:sequence>
<xs:element ref="kontakt" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- Kommentar -->
<xs:element name="kontakt">
<xs:complexType>
<xs:sequence>
<xs:element name="vorname" type="xs:string" minOccurs="0" maxOccurs="3"/>
<xs:element name="nachname" type="xs:string"/>
<xs:element name="adresse">
<xs:complexType>
<xs:sequence>
<xs:element name="strasse" type="xs:string"/>
<xs:element name="plz">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9][0-9][0-9][0-9][0-9]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="stadt" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
|
Zusätzliches Attribut mit lokal definiertem "simpleType".
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="adressbuch">
<xs:complexType>
<xs:sequence>
<xs:element ref="kontakt" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- Kommentar -->
<xs:element name="kontakt">
<xs:complexType>
<xs:sequence>
<xs:element name="vorname" type="xs:string" minOccurs="0" maxOccurs="3"/>
<xs:element name="nachname" type="xs:string"/>
<xs:element name="adresse" maxOccurs="3">
<xs:complexType>
<xs:sequence>
<xs:attribute name="art" use="required">
<xs:simpleType>
<xs:restriction base="xsd:string">
<xs:enumeration value="geschäftlich"/>
<xs:enumeration value="privat"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:element name="strasse" type="xs:string"/>
<xs:element name="plz">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9][0-9][0-9][0-9][0-9]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="stadt" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
|