Tags

If XML markup is a structural skeleton for a document, then tags are the bones. They mark the boundaries of elements, allow insertion of comments and special instructions, and declare settings for the parsing environment. A parser, the front line of any program that processes XML, relies on tags to help it break down documents into discrete XML objects. There are a handful of different XML object types, listed in Table 2-1.

Table 2-1. Types of tags in XML

Object

Purpose

Example

empty element

Represent information at a specific point in the document.

<xref linkend="abc"/>

container element

Group together elements and character data.

<p>This is a paragraph.</p>

declaration

Add a new parameter, entity, or grammar definition to the parsing environment.

<!ENTITY author “Erik Ray">

processing instruction

Feed a special instruction to a particular type of software.

<?print-formatter force-linebreak?>

comment

Insert an annotation that will be ignored by the XML processor.

<!— here’s where I left off —>

CDATA section

Create a section of character data that should not be parsed, preserving any special characters inside it.

<![CDATA[Ampersands galore! &&&&&&]]>

entity reference

Command the parser to insert some text stored elsewhere.

&company-name;

Elements are the most common XML object type. They break up the document into smaller and smaller cells, nesting inside one another like boxes. Figure 2-1 shows the document in Chapter 1 partitioned into separate elements. Each of these pieces has its own properties ...

Get Learning XML, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.