Thursday

DTD Example

DTD stands for Document Type Definition. The DTD specifies the grammatical structure of an XML document, thereby allowing XML parser to understand and interpret the document's content. The DTD contains the list of tags that are within XML document, their types and attributes. More specifically, the DTD defines the way elements relate to one another within the document's tree structure and specifies the attributes, which may be used within certain elements. The DTD provides parser with clear instructions on what to check for when they determine the validity of an XML document.

Following is the XML file example using DTD

<?xml version="1.0"?>

<!DOCTYPE SHOWROOM

[
<!ELEMENT SHOWROOM (TV|LAPTOP)+>

<!ELEMENT TV (#PCDATA)>

<!ATTLIST TV count CDATA #REQUIRED>

<!ELEMENT LAPTOP (#PCDATA)>

<!ATTLIST LAPTOP count CDATA #REQUIRED>
]
>
<SHOWROOM> ELECTRONIC GOODS

<TV count="10"> SONY </TV>

<TV count="15"> PANASONIC </TV>

<TV count="5"> PHILIPS </TV>

<TV count="9"> LG </TV>

<TV count="20"> NIKSON </TV>

<LAPTOP count="8"> TOSHIBA </LAPTOP>

<LAPTOP count="12"> HP </LAPTOP>

<LAPTOP count="7"> COMPAC </LAPTOP>

<LAPTOP count="18"> IBM </LAPTOP>

<LAPTOP count="2"> DELL </LAPTOP>

</SHOWROOM>


The picture blow show the result on the browser.

No comments: