Some
XML DTD examples
Lots of
working examples of XML and DTD are available in the internet. Let us
consider a sample XML file of the format given under,
_______________________________________________
<?xml
version="1.0" ?>
<videos>
<music>
<title>Video Title 1 </title>
<artist>Artist 1 </ artist >
</music>
< music >
<title>Video Title 2 </title>
< artist > Artist 2 </ artist >
< artist > Artist 3 </ artist >
</ music >
</ videos >
The above
XML file has data related to music videos. In this XML file the root
node is the <videos> and this can have any number of <music>
elements. The <music> element can have a single <title>
and any number of <artist> child nodes. For this structure you
can write the DTD as,
<!ELEMENT
videos ( music+ ) >
<!ELEMENT music ( title, artist+ ) >
<!ELEMENT title ( #PCDATA ) >
<!ELEMENT artist ( #PCDATA ) >
The ELEMENT
word indicates that the word next to that is an element and the nodes
of that particular element are given in the brackets. The + sign after
the node in the bracket denotes that it could be any number of nodes.
The #PCDATA indicates that it is a text node that has some value in
it.