XML Tutorials

  Home arrow XML Tutorials arrow Page 3 - Validation with Document Type Definiti...
XML TUTORIALS

Validation with Document Type Definitions (DTDs)
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2009-02-25

    Table of Contents:
  • Validation with Document Type Definitions (DTDs)
  • Getting to Know DTDs
  • Creating an XML Prolog
  • Whitespace

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Validation with Document Type Definitions (DTDs) - Creating an XML Prolog


    (Page 3 of 4 )

     

    A Prolog is the first thing in your XML document, and it is the first thing that will get processed. It contains five parts, some of which are optional. These parts are the declaration, the DOCTYPE declaration, instructions for the processor, white space, and comments. 

    XML Declaration 

    We have gone over this portion many times, so I will not bother to cover it again here. All you need to know now is that it is a part of the XML Prolog. 

    DOCTYPE 

    The DOCTYPE declaration tells the processor where to find your DTD. It is not truly XML, and is therefore written using SGML syntax. Here is an example of how you write the DOCTYPE: <!DOCTYPE albums SYSTEM “albums.dtd”> 

    This is a breakdown of how the above example works. !DOCTYPE signifies the beginning of a DOCTYPE declaration. Albums is the name of the DTD that we are using. SYSTEM “albums.dtd” is a way of telling the processor to look for a file called “albums.dtd.” 

    There are more ways to call a DTD file. In our above example, we are using a URI or a Uniform Resource Identifier. These are similar to URLs and truthfully, a URL is a form of a URI. The way we set up our reference to the DTD file via a URI above, means that the file “albums.dtd” is located in the same folder as our XML file. If your DTD file were located outside of the folders of your XML file, you would simply point to the URL where the DTD is located, such as http://www.mywebsite.com/file/albums.dtd

    Commenting 

    You should be familiar with the concept of commenting. It is the process of leaving notes/comments in your programs for other programmers or yourself. The computers and processors cannot see these comments and ignore them. Here is how you would write a comment in your file:

    <! – I am leaving a comment -- > 

    You must never leave a comment inside of an element and always make certain that you do not write a hyphen or double hyphen inside of the comment text, as it will confuse the processor. Here is what I mean: 

    <! – Hi – How are you? --> 

    When the processor sees the double hyphen after the word “Hi,” it will think that that is the end of the comment and treat the rest as normal syntax, causing errors. 

    More XML Tutorials Articles
    More By James Payne

    blog comments powered by Disqus

    XML TUTORIALS ARTICLES

    - Validation with Document Type Definitions (D...
    - Creating a Well-Formed XML Document
    - Getting to Know XML
    - A Friendly Approach to XML
    - Creating RSS 2.0 Feeds
    - Using Modules in Your RSS Feed
    - RSS 2.0
    - Querying XML: Use Cases
    - Joins and Query Use with XML
    - Solving Problems by Querying XML
    - Performing Set Operations When Querying XML
    - Querying XML
    - Handling Data for Ajax with JSON
    - Handling XML Data for Ajax
    - XML and JSON for Ajax


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap