What is a valid XML document.

Q3. What is a valid XML document?

Ans. A valid XML document is not only a well-formed document but also one that conforms to the DTD rules. DTD rules help in defining the structure of XML documents with a list of valid elements. The following code snippet shows an example of a DTD document:

<?xml version=”1.0”?>

<!DOCTYPE email [

<!ELEMENT email (to, from, heading, body)>



<!ELEMENT heading (#PCDATA)>



As you can see in the preceding code, we have defined DTD rules for the structure of an XML document. We have defined email as a parent element, which contains the four child elements: to, from, heading, and body. #PCDATA implies that all these elements will be parsed by the XML parser.

Leave a Reply

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

%d bloggers like this: