Understanding XML DTD through an example

Knowing the different components of a DTD file would help you in understanding how the XML file is formed based on a DTD.

The DTD file defines the rules on how the elements of the XML file should be organized. The number of child nodes for a particular node and the type of value of the particular node are all defined in a DTD.

Look at the following DTD file,

<!ELEMENT books ( book+ ) >
<!ELEMENT book ( title, author ) >
<!ELEMENT title ( #PCDATA ) >
<!ELEMENT author ( #PCDATA ) >

The 'ELEMENT' defines that the name that follows that word is an element of the XML file. Take the first statement. In that there is an element 'books' defined and that 'books' element can have any number of 'book' element as its child. That is why it is given as 'book+'. Now come to the second statement. It states that the 'book' element can have child elements as 'title' and 'author' and there can be only one 'title' and one 'author' element within the 'book' element. That is why the '+' is missing in it. The 'title' and the 'author' are text nodes that have some value in it. That is denoted by #PCDATA. Based on the above definition a typical XML document might look like,

<books>
<book>
<title >Book Title 1</title>
<author>Author 1</author>
</book>
<book>
<title>Book Title 2</title>
<author>Author 2</author>
</book>
<book>
<title>Book Title 3</title>
<author>Author 3</author>
</book>
</books>

There could be any number of 'book' elements in this XML file according to the DTD document.



.

SetApp - 100 Apps for everything you ever wanted to do on Mac

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

 

 

“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”

Copyright - © 2004 - 2019 - All Rights Reserved.