Exploring an XML Document

The XML specification defines a standard way to add markup to documents. XML users can create their own tags, which relate to their content. Here is an example of an address book, which shows a complete XML document with user-defined tags:

<?xml version="1.0"?>

<classlist>
  <student gender="m">
    <name>
      <firstname>John</firstname>
      <middleinitial>M</middleinitial>
     <lastname>Doe</lastname>
    </name>
    <address>
      <street>10 Main St.</street>
      <city>Sacramento</city>
      <state>CA</state>
      <zip>95814</zip>
    </address>
    <phone areacode="916">123-4567</phone>
    <email>[email protected]</email>
  </student>
</classlist>

The preceding XML document contains data about a class list, marked up with tags that describe their contents. The <classlist> tag is the root tag, and the <name>, <address>, <phone>, and <email> tags are used to describe different properties of the <student>'s tag. For example, the <name> tag consists of the <firstname>, <middleinitial>, and <lastname> tags, which contain the person's first name, middle initial, and last name, respectively.

Parts of an XML Document

An XML document consists of a prolog and a body. The prolog is used for declarations, and it consists of two internal blocks: the XML version and Document Type Declaration (DTD). The XML version is an optional block, which defines the version of the XML specification used in the document. The XML version is the first line of the document. Here's an example of a version declaration:

<?xml version = "1.0" ?>

The second block declares the data type declaration used. The DTD block is also optional; it defines a set of rules to which the XML document conforms. DTD will be covered in more detail later in this appendix.

The body of an XML document contains the root element tag that encompasses all other markup used for other contents in the document. The earlier listing is an example of the body section, with the <classlist> as the root tag. Figure C.1 depicts all the parts of a XML document.

Figure C.1. The parts of an XML document.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.31.67