XML Tutorials

  Home arrow XML Tutorials arrow Page 4 - Creating a Well-Formed XML Document
XML TUTORIALS

Creating a Well-Formed XML Document
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2009-02-18

    Table of Contents:
  • Creating a Well-Formed XML Document
  • Mark Up
  • Getting a Root Element
  • Well-Formed

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Creating a Well-Formed XML Document - Well-Formed


    (Page 4 of 4 )

     

    The above document is well-formed, and we have accomplished our goals. However, our document is still not validated. In order to achieve validation, we will have to set rules for our document. These rules include in what order the elements should be, whether they are required or optional, and how many times they are allowed to appear in a document. The only way to set these rules is via DTD and XML Schemas, which we will begin covering in the next article. 

    Before I leave you though, I would like to give you this list, which shows all the rules you must follow to create a well-formed document. 

    1. Use an XML declaration.

    2. Choose a root element that will encapsulate all other elements in your document.

    3. If an element has content, you must have an open tag and a close tag.

    4. If an element has no content, it must end with a forward-slash(/). Here is an example: <album genre="Rock and Roll" /> Note that there is no content, only an attribute.

    5. Nest your tags properly. Close all child tags PRIOR to closing a parent tag, and close the root tag last.

    6. If you have an attribute with a value, make sure that the value is enclosed in quotation marks (" ").

    7. Ensure all tags are formed properly. Opening tags are like this <sample> and closing tags are like this </sample> 

    There are editors that can help ensure your document is well-formed; we will discuss those in a later article. 

    Final Words  

    You should now know the rules for a well-formed document. In the next few articles you will learn how to use Document Type Definitions (DTDs) and XML Schema to validate and give rules to your documents. 

    Thank you for reading my article. If you have any questions or comments, please feel free to leave them.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.
    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 10 - Follow our Sitemap