How to build XML DTD

If you know how you want your XML document to be, then you can easily create an XML DTD. First you should be clear in your requirement for the XML document. The next step is to know the syntax of the DTD and how to create it.


_______________________________________________

Suppose you want your XML document to hold the data regarding music CDs. Then you might require a <title> element that would hold the title of the music CD. Then each of that title might have some artists who were involved in creating that CD.

So it is necessary for a tag like <artist> to be present. There could be more than one artist in creating that CD. So, multiple <artist> elements are needed. Based on these you can create a DTD as given below:

<!ELEMENT music ( cd+ ) >
<!ELEMENT cd ( title, artist+ ) >
<!ELEMENT title ( #PCDATA ) >
<!ELEMENT artist ( #PCDATA ) >

If you examine the above DTD you will find that the ELEMENT keyword is used to define an element. The word following that keyword is the name of the element and the words within the bracket indicate the child elements.

So, from the above code you will find that the root element is <music> and it would have one of more <cd> elements. One or More is indicated by the '+' sign. The <cd> element would have <title> and <artist> element.

The '+' sign indicates that there would be one or more <artist> element. The PCDATA indicates that the element would hold only text data that is parsed.



_______________________________________________

FREE Subscription

Subscribe to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.

Name:
Email:

Note : We never rent, trade, or sell my email lists to
anyone. We assure that your privacy is respected
and protected.

_______________________________________



 

FREE Subscription

Stay Current With the Latest Technology Developments Realted to XML. Signup for Our Newsletter and Receive New Articles Through Email.

Name:

Email:

Note : We never rent, trade, or sell our email lists to anyone. We assure that your privacy is respected and protected.

 

 

Add to My Yahoo!

Visit XML Training Material Guide Homepage

 

 

Copyright - © 2004 - 2017 - All Rights Reserved.