XML Tutorials
  Home arrow XML Tutorials arrow 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


    (Page 1 of 4 )

    This article will teach you how to create your first well-formed XML document. I will go through the various rules for creating a well-formed document, beginning with the XML declaration. By the end of the article you will have a firm grasp on how to create well-formed documents in XML.

    In our previous article we looked at the basic architecture of an XML document. We learned to create root, parent, and child structures, and put this into practice by creating a taxonomy of fields necessary for a music store.

    Part of this article will rehash what we learned in our last article, adding more depth and understanding. First, however, we will look at the XML declaration, as promised above. 

    XML Declarations  

    In XML documents, the first thing that you are required to input is the declaration. With this statement, you declare that the XML document is compliant. This is the first line that you will see in your XML document. Here is how it should be written: 

    <?xml version="1.0"?> 

    Or, if you are using XML version 1.1, you would write: 

    <?xml version="1.1"?> 

    The processor will garner certain information from the above declaration. First, It will learn that the document is an XML document and second, it will know upon which version of XML the document is built. 

    You can also add the standalone attribute and a value to the declaration. This informs the processor that your document does not rely on any other document to work (if the value is set to yes, mind you). If you set your attribute to yes in this manner, you can still call on style sheets, DTDs, schemas, etc. You are simply telling the processor that it will have to look no further than this document for actual content. 

    To add the standalone attribute, you write the declaration like this: 

    <?xml version="1.0" standalone="yes"?> 

    You may also want to indicate which encoding you will be using. You can do this by specifying your encoding attribute. There are different encoding attributes from which to choose, but for now we will use UTF 8, or the standard 8-bit ASCII character-set. Here is how you would write the declaration including the encoding attribute: 

    <?xml version="1.0" standalone="yes" encoding="UTF-8"?> 

    The XML declaration is a part of what is known as the XML prolog, and can include more data than we have seen here. We will cover these other attributes in a later article however. For now, be satisfied with these basics. 

    More XML Tutorials Articles
    More By James Payne


     

    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 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek