Derniers tutoriels de développement web
 

XSD Comment?


Les documents XML peuvent avoir une référence à une DTD ou un schéma XML.


Un document XML simple

Regardez ce document XML simple 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 de la note d'avoir quatre éléments enfants: "to, from, heading, body" .

Ligne 2-5 définit la destination, en provenance, position, éléments du corps pour être de type "#PCDATA" .


Un schéma XML

L'exemple suivant est un fichier XML Schema 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="http://www.w3ii.com"
xmlns="http://www.w3ii.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 de note est un complex type , car il contient d' autres éléments. Les autres éléments (to, from, heading, body) sont des simple types 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 a une référence à une DTD:

<?xml version="1.0"?>

<!DOCTYPE note SYSTEM
"http://www.w3ii.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 a une référence à un schéma XML:

<?xml version="1.0"?>

<note
xmlns="http://www.w3ii.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3ii.com note.xsd">
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>