Comment utiliser le schéma XML
documents XML contre un DTD ou schéma XML peuvent être référencés.
Un document XML simple:
Regardez ce, appelé document XML "de note.xml":
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
fichier DTD
L'exemple suivant est le fichier DTD nommé "note.dtd", son au-dessus du document XML ( "de note.xml") éléments sont définis:
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
La première ligne définit l'élément de note comporte quatre sous-éléments: "pour, à partir, à la tête, le corps".
2-5 ligne définit la destination, en provenance, position, élément de type de corps est "#PCDATA".
XML Schema
L'exemple suivant est le fichier de schéma XML appelé "note.xsd", qui définit le document XML ci-dessus ( «note.xml») éléments:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
élément de note est un type complexe, car il contient d'autres éléments de l'enfant. Autres éléments (à, à partir, à la tête, le corps) est un type simple, car ils ne contiennent pas d'autres éléments. Vous en apprendrez plus sur les types de types simples et complexes de la connaissance dans les sections suivantes.
Une référence à la DTD
Ce fichier contient une référence à une DTD:
<!DOCTYPE note SYSTEM
"http://www.w3schools.com/dtd/note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Une référence au schéma XML
Ce fichier contient une référence au schéma XML:
<note
xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>