The Header

The first syntax we look at is XML itself. An XML document can be broken into two basic pieces: the header, which gives an XML parser and XML applications information about how to handle the document, and the content, which is the XML data itself. Although this is a fairly loose division, it will help us differentiate the instructions to applications within an XML document from the XML content itself, and is an important distinction to understand. In our example, we will begin with the first several lines, which lead up to the JavaXML:Book element. These initial lines, excluding the JavaXML:Book element, make up the document header. The term “header” is not a formal term defined in the XML specification, but is commonly used in the XML community, and we will use it in this book to denote these initial lines of an XML document.

XML Instructions

The first statement you will see in any XML document is an XML instruction. XML instructions are actually a specific subset of processing instructions (PIs), which we talked about in the last chapter. Remember that we said PIs are generally passed on from the parser to the calling application, and handled there. However, PIs that specify their target as xml are intended for the XML parser itself. They specify the version of XML being used, a stylesheet, or other information that a parser may need to know to properly parse XML data. Here is an XML instruction:

<?xml version="1.0" standalone="no"?>

Like any other PI, it is of the form ...

Get Java and XML 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.