Sams Teach Yourself XML in 21 Days

Sams Teach Yourself XML in 21 Days

By Steven Holzner

Creating Prologs

Prologs appear at the beginning of XML documents, and contain information about the rest of the document. A prolog can contain XML declarations, XML comments (which describe the document), processing instructions, whitespace, and doctype declarations (doctype declarations are DTDs, which we'll see in Days 4 and 5). You don't need a prolog in an XML document for the document to be well formed. However, W3C says you should include at least an XML declaration in all XML documents.

There's a sample prolog at the beginning of this XML document containing an XML declaration, a processing instruction, and a DTD (which is stored in a <!DOCTYPE> element):


   <?xml version = "1.0"?>

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

   <!DOCTYPE document [

   <!ELEMENT document (employee)*>

   <!ELEMENT employee (name, hiredate, projects)>

   <!ELEMENT name (lastname, firstname)>

   <!ELEMENT lastname (#PCDATA)>

   <!ELEMENT firstname (#PCDATA)>

   <!ELEMENT hiredate (#PCDATA)>

   <!ELEMENT projects (project)*>

   <!ELEMENT project (product,id,price)>

   <!ELEMENT product (#PCDATA)>

   <!ELEMENT id (#PCDATA)>

   <!ELEMENT price (#PCDATA)>

   ]>
<document>
    <employee>
        <name>
            <lastname>Kelly</lastname>
            <firstname>Grace</firstname>
        </name>
        <hiredate>October 15, 2005</hiredate>
        <projects>
            <project>
                <product>Printer</product>
                .
                .
                .

The first item in a prolog should always be an XML declaration, and you'll take a look at this item next.

Share ThisShare This

Informit Network