Document Type Definition (DTD)
As should you know by now, XML by itself only serves to deliver data. You must provide other files to format and validate the XML code. This is where the DTD and schema come into play. The advancement of technology has provided many ways to validate XML. The DTD is just one. Document Type Definitions provide rules the computer can follow when processing the code. The DTD and schema are the precursors to XSL. Although still used in some formats, learning to write these files is not a requirement to create XML platforms, but it is indispensable to know what they are and how they function. These are terms you will stumble across in your studies frequently and understanding the basic design will be an advantage.What is a DTDThis is an explanation of document type definitions and the role they play in XML design. DTD code comes in two forms, internal and external. This article provides a description and explanation of how DTD files work.The DTD: Elements, Entities, Attributes, and NotationsA document type definition explains the validation rule for elements, entities, attributes and notations. A XML processor will look at the DTD and compare the rules with the code in the corresponding XML page. Step-by-step and line-by-line, the processors validates the XML code to ensure it follows the defined rules.
Valid XML
XML is a markup language used to create other markup languages, and the DTD is the tool you use to create and describe your language. Once a DTD is created and a document written based on that DTD, the document is then compared to the DTD. This is called validation. If your XML document follows the rules listed in the DTD, then the document is said to be valid. XML documents that don't follow the rules in their DTDs are called invalid.For example, while we haven't gone over the structure of a DTD yet, here is part of a simple one. It states that there is a root element called "family" that has two possible elements within it: "parent" and "child":
<!DOCTYPE family [
<!ELEMENT parent (#PCDATA)>
<!ELEMENT child (#PCDATA)>
]>
If you were to write an XML document based upon that DTD, you could write:
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE family [
<!ELEMENT parent (#PCDATA)>
<!ELEMENT child (#PCDATA)>
]>
<family>
<parent>Judy</parent>
<parent>Layard</parent>
<child>Jennifer</child>
<child>Brendan</child>
</family>
This would be a valid XML document. But if I added extra text outside of the <parent> or <child> tags, the document would be invalid until I changed the DTD:
...
<family>
This is my family:
<parent>Judy</parent>
<parent>Layard</parent>
<child>Jennifer</child>
<child>Brendan</child>
</family>
Source: www.about.com
Valid XML
XML is a markup language used to create other markup languages, and the DTD is the tool you use to create and describe your language. Once a DTD is created and a document written based on that DTD, the document is then compared to the DTD. This is called validation. If your XML document follows the rules listed in the DTD, then the document is said to be valid. XML documents that don't follow the rules in their DTDs are called invalid.For example, while we haven't gone over the structure of a DTD yet, here is part of a simple one. It states that there is a root element called "family" that has two possible elements within it: "parent" and "child":
<!DOCTYPE family [
<!ELEMENT parent (#PCDATA)>
<!ELEMENT child (#PCDATA)>
]>
If you were to write an XML document based upon that DTD, you could write:
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE family [
<!ELEMENT parent (#PCDATA)>
<!ELEMENT child (#PCDATA)>
]>
<family>
<parent>Judy</parent>
<parent>Layard</parent>
<child>Jennifer</child>
<child>Brendan</child>
</family>
This would be a valid XML document. But if I added extra text outside of the <parent> or <child> tags, the document would be invalid until I changed the DTD:
...
<family>
This is my family:
<parent>Judy</parent>
<parent>Layard</parent>
<child>Jennifer</child>
<child>Brendan</child>
</family>
Source: www.about.com
Comments
Post a Comment