XML Tutorials

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

    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

    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

    Developer Shed Affiliates

     



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