Modularizing XML
XML entities and namespaces provide two techniques to modularize the contents of XML documents. In this section we study simple examples of both.
Including Text and External Resources
Entities are a
mechanism for defining named string substitution variables in your
XML file. They can save typing repetitive text in your documents. For
example, if the Frequently Asked Questions document that we’re
working on is for the Oracle JDeveloper 3.1 product, the text
Oracle
JDeveloper
and the
current version number of the product might appear in many of the
questions and answers. We can define two entities to represent this
repetitive text using the syntax:
<!ENTITY jdev "Oracle JDeveloper"> <!ENTITY ver "3.1">
With these in place we can refer to the entities by name in the
contents of our FAQ.xml
document with the
syntax:
<Question>What is the current version of &jdev;?</Question> <Answer>The current version is &jdev; &ver;</Answer>
The syntax for user-defined entities is identical to that of the
built-in entities we saw earlier (<
,
>
, '
, and
"
). References to user-defined entities
like &jdev;
start with an ampersand character
and end with a semicolon, with the entity name in between. Like the
default attribute values we saw earlier, these entities can be
defined in an external DTD file, or right in the current document by
including them in the local DTD section known as the
internal subset
. The syntax for including these entity definitions in the document ...
Get Building Oracle XML Applications 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.