background image

Rules for Using the Attributes

<< Generating a Document Type Declaration | Identifying the JSP Document to the Container >>
<< Generating a Document Type Declaration | Identifying the JSP Document to the Container >>

Rules for Using the Attributes

The rules for using the attributes are as follows:
The doctype attributes can appear in any order.
The doctype-root attribute must be specified if the doctype-system attribute is specified.
The doctype-public attribute must not be specified unless doctype-system is specified.
This syntax notation summarizes these rules:
<jsp:output (omit-xmldeclaration=
"yes"|"no"|"true"|"false"){doctypeDecl} />
doctypeDecl:=
(doctype-root-element=
"rootElement"
doctype-public=
"PublicLiteral"
doctype-system=
"SystemLiteral")
| (doctype-root-element=
"rootElement"
doctype-system=
"SystemLiteral")
Suppose that you want to reference a DTD, called books.DTD, from the output of the
books.jspx
page. The DTD would look like this:
<!ELEMENT books (book+) >
<!ELEMENT book (surname, firstname, title, price, year,
description, inventory) >
<!ATTLIST book id CDATA #REQUIRED >
<!ELEMENT surname (#PCDATA) >
<!ELEMENT firstname (#PCDATA) >
<!ELEMENT title (#PCDATA) >
<!ELEMENT price (#PCDATA) >
<!ELEMENT year (#PCDATA) >
<!ELEMENT description (#PCDATA) >
<!ELEMENT inventory (#PCDATA) >
To add a document type declaration that references the DTD to the XML request output
generated from books.jspx, include this jsp:output element in books.jspx:
<jsp:output doctype-root-element=
"books"
doctype-system=
"books.DTD" />
With this jsp:output action, the JSP container generates this document type declaration in the
request output:
<!DOCTYPE books SYSTEM
"books.DTD" />
The jsp:output need not be located before the root element of the document. The JSP
container will automatically place the resulting document type declaration before the start of
the output of the JSP document.
Note that the JSP container will not interpret anything provided by jsp:output. This means
that the JSP container will not validate the XML document against the DTD. It only generates
Creating a JSP Document
Chapter 6 · JavaServer Pages Documents
199