Skip to Main Content
Java Enterprise Best Practices
book

Java Enterprise Best Practices

by O'Reilly Java Authors
December 2002
Intermediate to advanced content levelIntermediate to advanced
288 pages
9h 46m
English
O'Reilly Media, Inc.
Content preview from Java Enterprise Best Practices

Use Parameter Entities

The natural extension of using entity references in an XML document is using parameter entities in a DTD. A parameter entity looks very much like an entity reference:

<!ENTITY % common.attributes
    'id        ID    #IMPLIED
     account   CDATA #REQUIRED'
>

Here, a more strict textual replacement occurs. In this case, the common.attributes definition can be used to specify two attributes that most elements in a constraint set should have. You can then define those elements in the DTD, as shown in Example 5-2.

Example 5-2. Sample DTD with parameter entities
<!ELEMENT purchaseOrder (item+, manufacturer, purchaser, purchaseInfo)>
<!ATTLIST purchaseOrder %common.attributes;>
   
<!ELEMENT item (price, quantity)>
<!ATTLIST item %common.attributes;>
   
<!ELEMENT manufacturer (#PCDATA)>
<!ATTLIST manufacturer %common.attributes;>
   
<!ELEMENT purchaser (#PCDATA)>
<!ATTLIST purchaser %common.attributes;>
   
<!ELEMENT purchaseInfo (creditCard | check | cash)>

In Example 5-2, each element uses the common.attributes parameter entity, which will be converted into the string in the example (including the id and account attributes). This is done for each attribute list. And, like entity references, changing the value of the parameter entity changes the definitions for all elements. Again, this technique can be used to clean up the organization of your DTDs.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Moving to Java 9: Better Design and Simpler Code

Moving to Java 9: Better Design and Simpler Code

Trisha Gee
Java EE 8 High Performance

Java EE 8 High Performance

Romain Manni-Bucau

Publisher Resources

ISBN: 0596003846Supplemental ContentErrata Page