XML Tutorials

  Home arrow XML Tutorials arrow Page 2 - 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) - Getting to Know DTDs


    (Page 2 of 4 )

     

    Now that we know what document descriptions are and whether or not we should use one, we can begin learning about the first type, document type definitions or DTDs. 

    Before we begin however, it is important to know one thing: if you do decide to use a DTD to validate your XML, you must make sure your document is valid; certain processors will cease to operate if they encounter invalid documents. So think carefully before using them. 

    On the flip side, DTDs can help maintain structure and integrity within your data. A DTD gives definition to the elements and attributes that make up your document. Think of it as a form of grammar. The reason  DTDs are optional in XML is because XML itself (when written properly) is well-formed, and processors can sometimes get the gist of what rules you are implying. 

    Below is a list of some terms you should know when dealing with DTDs. 

    Document Type Declaration (DOCTYPE) – This declaration comes after the XML declaration we learned before, and tells the processor where the DTD file is located.

    It can look like this: <!DOCTYPE Root-Element SYSTEM “nameofthefile.dtd”> 

    Element Type Declaration – Used to give definition to an element type. An example would be: <!ELEMENT Name(#PCDATA)> 

    Attribute-list Declaration – Used to give definition to a datatype, default value, and name for each attribute associated with an element. An example of this would be: <!ATTLIST Element-Name Name Datatype Default> 

    Entity Declaration – Used to give definition to data referenced by an entity. An example of this would be: <!ENTITY Entity-Name “text”> . We will discuss entities more in a later article. 

    Notation Declaration – Gives association to a notation name with data that is used to find an interpreter program that is typically external, when XML processors cannot do so themselves. An example would be <!NOTATION NameSystem “externalID”> 

    XML Declaration – Informs the processor as to which version of XML you are using. An example would be <?xml version=”1.0” encoding=”UTF-8”?> 

    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 11 - Follow our Sitemap