1. Home
  2. Computing & Technology
  3. Web Design / HTML
Anatomy of an XML Document
What are the parts of XML?

 Related Resources
• XML Elements
• Attributes and XML
• Examining XML
• XML Information
 
 Stay Up-to-Date
  with Web Design
  Email:
  

By Jennifer Kyrnin

Whether you're writing XML from scratch, or writing a document from a pre-defined specification there is a standard layout for XML. Here is a standard XML document:

<?xml version="1.0"?>
<workorder priority="high" datedue="09/30/2001">
  <submitter>
    <name first="Jennifer" last="Kyrnin" />
    <email>html.guide@about.com</email>
    <account number="11001100" />
  </submitter>
  <project title="update aa051198.htm article">
    <url>http://webdesign.about.com/library/weekly/aa051198.htm</url>
    <description>
    Please convert this article to the new article look and feel, with the side     navigation and information.
    </description>
  </project>
</workorder>

If you look closely at this markup, you will be able to determine its structure. The first part of the structure is the XML declaration, <?xml version="1.0"?>. Everything after that is an element of the XML document. The container element is <workorder>. This element contains all the other elements and surrounds them all. Inside of that element are the specialized elements that describe the rest of the document, such as <submitter>, <project>, and <account>.

Here is a more visual tree view of the structure:
tree structure of XML document - image courtesy Jennifer Kyrnin
Each of the elements are in red, with any attributes in dark blue, and contents in black.

This tree can have many more branches and sub-branches. Each branch represents an element, which can have attributes or not, and content or not.

The Prolog
This is the most vital part of our document. It tells the browser or parser that this document is marked up in XML. This prolog is actually a part of HTML as well, but most HTML authors leave it out. In HTML the prolog might look like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
This tells browser that this document will be using HTML 4.0 Transitional. The prolog in an XML document tells the computer that it's using XML and what version.

But the prolog for an XML document can also contain:

  • the DTD or schema being used
  • declarations of special pieces of text
  • text encoding
  • XML processor instructions

Elements
After the prolog, come the structure of the XML document, the elements. The most important thing to remember is that there must be a container element for your XML document. In fact, your document can be made up of one element alone:

<?xml version="1.0"?>
<topelement>
This XML document is a well-formed document, but it only has one element. This is OK. It is still a correct XML document.
</topelement>

Learn more about elements

Previous Features

Explore Web Design / HTML
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Web Design / HTML

©2009 About.com, a part of The New York Times Company.

All rights reserved.