Apr 3, 2008

XML Document Structure

XML Structure

This page provides a description of XML structure including the document parts, the prologue, and provides a simple XML example document.

Document Parts

  • Prolog
  • Document Element (root element)

The Prologue

The prologue, equivalent to the header in HTML, may include the following:

  • An XML declaration (optional) such as:

<?xml version="1.0"?>

  • A DTD or reference to one (optional). An example reference to an external DTD file:

<!DOCTYPE LANGLIST SYSTEM "langlist.dtd">

  • Processing instructions - An example processing instruction that causes style to be determined by a style sheet:

<?xml-stylesheet type="text/css" href="xmlstyle.css"?>

An XML Document

Therefore a complete well formed XML document may look like:

<?xml version="1.0"?>
<LAND>
   <FOREST>
      <TREE>Oak</TREE>
      <TREE>Pine</TREE>
      <TREE>Maple</TREE>
   </FOREST>
   <MEADOW>
      <GRASS>Bluegrass</GRASS>
      <GRASS>Fescue</GRASS>
      <GRASS>Rye</GRASS>
   </MEADOW>
</LAND>

The LAND element, above, is the root element.

The below document is not an XML document since it does not qualify by the rules of a well formed document. There is more than one top level element which disqualifies the document from being well formed.

<?xml version="1.0"?>
<FOREST>
   <TREE>Oak</TREE>
   <TREE>Pine</TREE>
   <TREE>Maple</TREE>
</FOREST>
<MEADOW>
   <GRASS>Bluegrass</GRASS>
   <GRASS>Fescue</GRASS>
   <GRASS>Rye</GRASS>
</MEADOW>

Defining Display

If the HTML document is not linked to a style sheet, the XML document will be displayed with tags included. The elements and tags may be color coded to aid in viewing the document. The document is displayed without tags according to the style sheet if a link to one is specified. The following document shows a document with a link to a cascading style sheet:

<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="xmlstyle.css"?>
<DATABASE>
   <TITLE>List of Items Important to Markup Languages</TITLE>
   <TITLE2>Languages</TITLE2>
      <LANGUAGES>SGML<LANGUAGES>
      <LANGUAGES>XML</LANGUAGES>
      <LANGUAGES>HTML<LANGUAGES>
   <TITLE2>Other</TITLE2>
      <OTHER>DTD<OTHER>
      <OTHER>DSSL<OTHER>
      <OTHER>Style Sheets</OTHER>
</DATABASE>

The below line, which is a part of the XML document above, is a processing instruction and is a part of the prolog.

<?xml-stylesheet type="text/css" href="xmlstyle.css"?>

The style sheet, "xmlstyle.css", may look like:

DATABASE 
     { display: block }
TITLE
     { display: block;
       font-family: arial;
       color: #008000; 
       font-weight: 600; 
       font-size: 22;
       text-align: center }
TITLE2
     { display: block;
       font-family: arial;
       color: #000080; 
       font-weight: 400; 
       font-size: 20 }
LANGUAGES
     { display: block;
       list-style-type: decimal;
       font-family: arial;
       color: #000000; 
       font-weight: 400; 
       font-size: 18 }
OTHER
     { display: block;
       list-style-type: square;
       font-family: arial;
       color: #0000ff; 
       font-weight: 200; 
       font-size: 14 }

No comments:

Post a Comment

Popular Posts