XML Elements

   

XML Document

In its simplest form, an XML document is one (and only one) element. This top-level element is called the root. However, because an element can contain other elements, the document can be large and complex.

The only rule to remember is that the document cannot have more than one root. The following is a valid XML document:

 <set>      <book isbn='0-672-32054-1'/>      <book isbn='0-7897-2215-1'/>   </set> 

XML Declaration

The document can start with an optional XML declaration. The declaration has a number of attributes to specify:

  • The version of XML in use (at this time 1.0 ). This attribute is required.

  • The character set encoding in use (if not using a standard Unicode encoding such as UTF-8 or UTF-16). This attribute is optional.

  • Whether the document is standalone; in other words, whether the XML parser must read an external file (such as the external DTD subset) to properly decode it. This attribute is optional.

The following document has a declaration with optional encoding and standalone attributes:

 <?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>     <set>        <book isbn='0-672-32054-1'/>        <book isbn='0-7897-2242-9'/>     </set> 

Document Type Declaration

An optional model can be associated to the document, such as a Document Type Definition (DTD), or another model, such as the forthcoming XML Schema. The document references the model in the document type declaration (not to be confused with the DTD):

 <?xml version="1.0"?>    <!DOCTYPE set SYSTEM "http://www.psol.com/axs/bookset.dtd">    <set>       <book isbn='0-672-32054-1'/>       <book isbn='0-7897-2242-9'/>    </set> 

The document type declaration can be any of the following:

  • SYSTEM , pointing to a system identifier (a file or an URI)

  • PUBLIC , including a so-called public identifier of the form -//Pineapplesoft//Book Set//EN

  • A copy of the model between square brackets

  • A combination of the above

   


Applied XML Solutions
Applied XML Solutions
ISBN: 0672320541
EAN: 2147483647
Year: 1999
Pages: 142

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net