background image

Generating a Document Type Declaration

<< Generating XML Declarations | Rules for Using the Attributes >>
<< Generating XML Declarations | Rules for Using the Attributes >>

Generating a Document Type Declaration

Neither a JSP document nor its request output is required to have an XML declaration. In fact, if
the JSP document is not producing XML output then it shouldn't have an XML declaration.
The JSP container will not include the XML declaration in the output when either of the
following is true:
You set the omit-xml-declaration attribute of the jsp:output element to either true or
yes
.
You have a jsp:root element in your JSP document, and you do not specify
omit-xml-declaration=
"false" in jsp:output.
The JSP container will include the XML declaration in the output when either of the following is
true:
You set the omit-xml-declaration attribute of the jsp:output element to either false or
no
.
You do not have a jsp:root action in your JSP document, and you do not specify the
omit-xml-declaration
attribute in jsp:output.
The books.jspx JSP document does not include a jsp:root action nor a jsp:output.
Therefore, the default XML declaration is generated in the output.
Generating a Document Type Declaration
A document type declaration (DTD) defines the structural rules for the XML document in
which the document type declaration occurs. XML documents are not required to have a DTD
associated with them. In fact, the books example does not include one.
This section shows you how to use the jsp:output element to add a document type declaration
to the XML output of books.jspx. It also shows you how to enter the document type
declaration manually into books.jspx so that the JSP container will interpret it and validate the
document against the DTD.
As shown in
Table 6­3
, the jsp:output element has three attributes that you use to generate the
document type declaration:
doctype-root-element
: Indicates the root element of the XML document.
doctype-system
: Indicates the URI reference to the DTD.
doctype-public
: A more flexible way to reference the DTD. This identifier gives more
information about the DTD without giving a specific location. A public identifier resolves to
the same actual document on any system even though the location of that document on each
system may vary. See the
XML 1.0 specification (http://www.w3.org/XML/)
for more
information.
Creating a JSP Document
The Java EE 5 Tutorial · September 2007
198