X hits on this document

458 views

0 shares

1 downloads

0 comments

23 / 142

Chapter 4. Document type definitions

Defining XML vocabularies with DTDs

Creating your own XML mark up is all well and good, but if you want to share your documents with other people you will need to communicate to these other people the vocabulary your XML documents understand. This is the semantic part of XML documents -- what elements do your XML files contain and how are the elements related to each other? These semantic relationships are created using Docu- ment Type Definitions (DTD) and/or XML Schemas. DTDs are legacy implementations from the SGML world. They are more commonly used than the newer, XML-based, XML Schemas. This section provides an overview for creating DTDs.

DTDs can exist inside an XML document or outside an XML document. If they reside in an XML docu- ment, then they begin with a DOCTYPE declaration followed by the name of the XML document's root element and finally a list of all the elements and how they are related to each other. Here is a simple DTD for embedded in the pets.xml file itself:

<!DOCTYPE pets [

<!ELEMENT

pets

<!ELEMENT

pet

<!ELEMENT

name

<!ELEMENT

age

<!ELEMENT

type

<!ELEMENT colo

(pet+)> (name, age, type, color)> (#PCDATA)> (#PCDATA)> (#PCDATA)> r (#PCDATA)>

]>

<pets> <pet> <name>Tilly</name> <age>14</age> <type>cat</type> <color>silver</color> </pet> <pet> <name>Amanda</name> <age>10</age> <type>dog</type> <color>brown</color> </pet> <pet>

15

Document info
Document views458
Page views464
Page last viewedFri Dec 09 11:40:51 UTC 2016
Pages142
Paragraphs3126
Words34660

Comments