XML - Managing Data Exchange/DTD
|Previous Chapter||Next Chapter|
|← Data schemas||XHTML →|
| This page or section is an undeveloped draft or outline.
You can help to develop the work, or you can ask for assistance in the project room.
A Document Type Definition is a file that links to an XML page. It controls what must or can be displayed, what attributes and their values must/can have and how the XML file should look like. XHTML, HTML and other markup languages use DTDs to validate their documents. Note: Web browsers accept bad markup in HTML.
Uses OF DTDsEdit
DTDs are used to store large amounts of data in a custom markup language that can be used for a specific program or organization. Like schemas they can have elements, attributes and entities. The only difference is how it is displayed.
Like in a schema, a DTD has a prolog. It is one line of text.
<?xml version="1.0" encoding="UTF-8"?>
The question mark is to tell the computer you are giving him an instruction. The word xml tells him that you are using XML, the version attribute tells what version of XML you are using and the encoding attribute tells him how to encode the data (you would use a different encoding if you wanted to use chinese text).
The element tag is used to display an element of the page, depending on how you declare it. It can go only on a specific part of the page or anywhere on the page.
The first element you declare is the root element (in HTML it's html). Let's pretend that there was an organization that wanted a bunch of XML files containing info about each person. They probably would have a root element of the file named "person". The standard for declaring an element with children elements is
<!ELEMENT elementName (childElement, childElement2, childElement3)>
So the orginization root element tag declaration would be
<!ELEMENT person (firstName, lastName, postalCode, cellNumber, homeNumber, email)>
Note: A child element must be declared in a separate element tag to be valid.
Note: The comma is used where you identify the child element is an occurrence indicator (something that tells the computer how it should occur). There are other occurrence indicators. We will cover them later in this chapter.
Note: The parentheses define what content type is found in the bracket. Different content types are found later in this chapter.
Some elements you don't want to be linked to specific tags (like a formatting tag you want to use to highlight important info), you do the same thing except you don't use it as a child element for any element depending on your needs, you may use the ANY content type, which allows you to use character data or other tags in your tag, the EMPTY content type, which looks like "<exampleXmlTag />" or #PCDATA for text.
Note:In an element declaration you can combine parentheses with #PCDATA. It looks like this <!ELEMENT elementName ( #PCDATA| childName). The pipe bar means that you can use text or other tags.