XML Tutorials
  Home arrow XML Tutorials arrow Page 4 - Creating a Well-Formed XML Document
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
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 / 4
    2009-02-18

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

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    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.

     

    XML TUTORIALS ARTICLES

    - Validation with Document Type Definitions (D...
    - Creating a Well-Formed XML Document
    - Creating XML Taxonomies
    - 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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek