XSD Comment ?
Les documents XML peuvent avoir une référence à une DTD ou à un schéma XML.
Un document XML simple
Regardez ce simple document XML appelé "note.xml":
<?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Un fichier DTD
L'exemple suivant est un fichier DTD appelé "note.dtd" qui définit les éléments du document XML ci-dessus ("note.xml") :
<!ELEMENT note (to, from, heading, body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
La première ligne définit l'élément note comme ayant quatre éléments enfants : "to, from, heading, body".
Les lignes 2 à 5 définissent les éléments de destination, de provenance, d'en-tête et de corps comme étant de type "#PCDATA".
Au schéma XML
L'exemple suivant est un fichier de schéma XML appelé "note.xsd" qui définit les éléments du document XML ci-dessus ("note.xml") :
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="https://www.w3schools.com"
xmlns="https://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'élément note est un type complexe car il contient d'autres éléments. Les autres éléments (to, from, header, body) sont des types simples car ils ne contiennent pas d'autres éléments. Vous en apprendrez plus sur les types simples et complexes dans les chapitres suivants.
Une référence à une DTD
Ce document XML fait référence à une DTD :
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM
"https://www.w3schools.com/xml/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 à un schéma XML
Ce document XML contient une référence à un schéma XML :
<?xml version="1.0"?>
<note
xmlns="https://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.w3schools.com/xml note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>