background image

Generating XML Declarations

<< Using the jsp:root Element | Generating a Document Type Declaration >>
<< Using the jsp:root Element | Generating a Document Type Declaration >>

Generating XML Declarations

The XML declaration and document type declaration that are declared by the jsp:output
element are not interpreted by the JSP container. Instead, the container simply directs them to
the request output.
To illustrate this, here is an example of specifying a document type declaration with
jsp:output
:
<jsp:output doctype-root-element=
"books"
doctype-system=
"books.dtd" />
The resulting output is:
<!DOCTYPE books SYSTEM
"books.dtd" >
Specifying the document type declaration in the jsp:output element will not cause the JSP
container to validate the JSP document against the books.dtd.
If you want the JSP document to be validated against the DTD, you must manually include the
document type declaration within the JSP document, just as you would with any XML
document.
Table 6­3
shows all the jsp:output attributes. They are all optional, but some attributes
depend on other attributes occurring in the same jsp:output element, as shown in the table.
The rest of this section explains more about using jsp:output to generate an XML declaration
and a document type declaration.
TABLE 6­3
jsp:output
Attributes
Attribute
What It Specifies
omit-xml-declaration
A value of true or yes omits the XML declaration. A value of false or no
generates an XML declaration.
doctype-root-element
Indicates the root element of the XML document in the DOCTYPE. Can be specified
only if doctype-system is specified.
doctype-system
Specifies that a DOCTYPE is generated in output and gives the SYSTEM literal.
doctype-public
Specifies the value for the Public ID of the generated DOCTYPE. Can be specified
only if doctype-system is specified.
Generating XML Declarations
Here is an example of an XML declaration:
<?xml version=
"1.0" encoding="UTF-8" ?>
This declaration is the default XML declaration. It means that if the JSP container is generating
an XML declaration, this is what the JSP container will include in the output of your JSP
document.
Creating a JSP Document
Chapter 6 · JavaServer Pages Documents
197