|
home—lects—hws
D2L—breeze (snow day)
Originally based on XML Visual Quickstart Guide by Kevin Howard Goldberg, and notes therefrom by Jack Davis (jcdavis@radford.edu).
An example file: the textbook's dtd/ch06-wonders.dtd, as referenced in ch06-wonders.xml (view-source, to see the DOCTYPE line).
Aside: The meaning of quotes. (Entities are used in similar situations.)
Entities are named-constants for your XML. With an entity, you define its name and the text it should expand into when referenced in an XML document. The entity reference is included in an XML document or DTD; it's replaced by defined-value upon rendering.
Define an entity whenever you want one “glyph” — something
that always renders as the same text-characters.
So
We will discuss “general entities” here. (We won't discuss “parameter entities”, which are entitities that don't render to part of a document; they render to part of an (enclosing) DTD.)
<story> The oldest of the &wow;, the Great Pyramid, is … </story>will render as “The oldest of the Wonders of the World, the Great Pyramid, is…”.
(remaining topics are optional — not frequently used:)
Unparsed entities are used to embed non-text or non-XML content into an XML document.
Note that current browsers (2012) don't [have XML parsers that] handle unparsed entities, even when specified correctly in the DTD.
The entities we've seen so far are called parsed entities
because the
XML parser looks at them and analyzes them in the course of parsing
through the XML document
(and recognizing them between “
Unparsed entities, on the other hand,
do not have entity references (that is,
you won't actually use them between
For example, in the following we'll suppose we
want to have an entity “
<!ELEMENT photo EMPTY> |
<!ENTITY lighthouse_pic SYSTEM "lighthouse.jpg" NDATA jpg> |
Here is another example that uses parsed and unparsed general entitities:
Viewing the
raw XML document
(note that usually the raw xml tree should be shown, but
most browsers will instead give an error on the entity they don't
understand).
Here's the xml document after being transformed by using XSLT.
Classic Cars 4 w/Photo Example
Parameter entities are used to reference external information in the DTD itself. However, they are not common in practice. You can see the text for details.
home—lects—hws
D2L—breeze (snow day)
©2014, Ian Barland, Radford University Last modified 2014.Nov.21 (Fri) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |