![]() |
|
| • All Online Courses • New Courses • QuickTips • Word Definitions • Submit a Tutorial • Links • |
|
Learn XML programming in this free XML training course Section 5: Document Type DefinitionsWhat are Document Type Definitions, or DTD’s?Document Type Definitions, also known as DTD’s, are one of the more common methods of working with XML. By using DTD’s, it’s possible to create specific definitions for each component of an XML document. DTD’s define a common set of elements and attributes, allowing you to refine the way that your XML documents operate. There are two different ways that you can work with DTD’s. The first is by using inline DTD’s, or DTD’s that are created within the document itself. These DTD’s are listed at the beginning of the document, and help to further define the elements contained within the root element. An example of this would look like: <!doctype cats_info [
<!element cats_info (#pcdata)>
Note the use of exclamation points and brackets, and how the element is imbedded within the brackets of the doctype declaration. The #pcdata is a reserved XML keyword which is used to let the browser know that cats_info can only contain characters. The second way to create a DTD is to create an external DTD, a separate file that contains all of your DTD data and is referenced from within the XML file (much like CSS and XSL files are referenced.) The file that you create will be saved with a .dtd extension, such as cats.dtd. You will then need to reference it from your XML file, using the declaration, as well as the system keyword. Your reference declaration will look something like this:
You would then create and declare your elements and the rest of your document as you did before. Note the use of exclamation points and brackets, and how the element is imbedded within the brackets of the doctype declaration. The is a reserved XML keyword which is used to let the browser know that can only contain characters.
What is DTD Validation?Validation is the process by which a browser uses a DTD to determine if the data being used by an element is appropriate for it to use. You’ve already seen a little bit of DTD validation in the example above… the reserved keyword #pcdata is used for validation, making sure that the element it’s used to define contains only characters. If the element contains anything other than character data, then the DTD will report an error to the browser and the page won’t be displayed. Here are other examples of validating rules that are used in DTD’s: (#pcdata)* Indicates that the element can only contain zero or more characters. (ElementOne) Indicates that the element contains one instance of ElementOne. (ElementOne+) Indicates that the element contains one or more instances of ElementOne. (ElementOne?) Indicates that the element contains zero or more instances of ElementOne. (ElementOne, ElementTwo) Indicates that the element contains one instance each of ElementOne and ElementTwo. (ElementOne | ElementTwo) Indicates that the element contains one instance of ElementOne or it contains one instance of ElementTwo. (#pcdata |ElementOne)* Indicates that the element consists of either multiple characters or one instance of ElementOne. Note that #pcdata needs to appear first. EMPTY Indicates that the element contains no content. ANY Indicates that the element may contain any content. Note that this should only be used when creating and checking documents, and shouldn’t appear in the final product (as it opens too many possibilities for errors.)
by John Casteele Find more free Internet tutorials from Learnthat.com. More Information:
Help us by rating this tutorial: [---] [--] [+] [++] [+++] [---] lowest; [+++] highest
|
|
||||||
![]() |
Learn: Free
Tutorials - Links
to Free Tutorials
Understand: Free Technical Definitions
- ExplainThat Whitepapers
Use: Certification Section -
Discussion Forum
Visit Our Network Sites:
About Us : Contact Us : Advertise : Privacy Information