DTD XML
XML è la sintassi corretta si chiama "buona forma" in XML.
convalida DTD di XML tramite un XML "legale".
Sotto forma di documenti XML ben formati
"Ben formato" documento XML ha una sintassi corretta.
regole di sintassi descritte nella sezione precedente:
- documento XML deve avere un elemento radice
- elementi XML devono avere un tag di chiusura
- I tag XML sono case sensitive
- elementi XML devono essere correttamente annidati
- valori degli attributi XML devono essere citati
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Convalidare i documenti XML
Legale documento XML è un "ben formato" documento XML, che è coerente con il Document Type Definition (DTD) regole:
<!DOCTYPE note SYSTEM "Note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Nell'esempio precedente, dichiarazione DOCTYPE è un riferimento a un file DTD esterno. I paragrafi seguenti mostrano il contenuto del file.
DTD XML
DTD destinato a definire la struttura dei documenti XML. Esso utilizza una serie di elementi giuridici per definire la struttura del documento:
[
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
Se volete saperne di DTD, si prega sulla nostra home page per trovare DTD tutorial.
XML Schema
W3C supporta un DTD basato su XML al posto di chi ha chiamato XML Schema:
<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>
Se volete saperne di XML Schema, si prega di nostra home page per trovare Schema tutorial.
Un validatore XML generica
Per aiutarvi a controllare la sintassi del file XML, abbiamo creato un validatore XML, in modo da poter controllare la sintassi per qualsiasi documento XML.
Vedere il prossimo capitolo.