DTD and Definition

We see big use of XML (eXtensible markup language) everywhere, especially in web programming and web services we do have to use XMLs. How is a simple XML file?

<?xml version="1.0"?>
<user>
<name>Tugrul</name>
<lastname>ASLAN</lastname>
<country>Turkey</country>
</user>

The below example we are using the given XML data we have the tags like <user> </user> but how do we define those? Here we have the answer DTD(Document Type Definition). Simply we define a DTD file like this:

<!DOCTYPE user
[
<!ELEMENT user(name,lastname,country)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>
<!ELEMENT country (#PCDATA)>
]>

here we have defined a definition for our xml schema. If I explain these attributes:

  • !DOCTYPE means that user is the root element of the defition and xml schema,
  • !ELEMENT user (name,lastname,country) defines that our schema will have three elements,
  • !ELEMENT defines each element
  • #PCDATA is last of all defines parse able text data

In xml the raw data has to be valid which does indicate that it needs to be a well formatted xml document which also identifies the rules of DTD. With the DTD you can identify your own XML tag format and add as many attributes as you wish.

Leave a Reply

Your email address will not be published. Required fields are marked *