Home arrow XML arrow Page 7 - The Fundamentals of DTD Design

An Entity In The Attic - XML

Ever tried to read a DTD, and failed miserably? Ever wondered what all those symbols and weird language constructs meant? Well, fear not - this crash course will get you up to speed with the basics of DTD design in a hurry.

  1. The Fundamentals of DTD Design
  2. DTD Who?
  3. Rainy Days
  4. Simply Elementary
  5. What's The Frequency, Bobby?
  6. Turning Up The Heat
  7. An Entity In The Attic
  8. The Old Popcorn Trick
By: Vikram Vaswani, (c) Melonfire
Rating: starstarstarstarstar / 6
September 27, 2001

print this article


XML entities are a bit like variables in other programming languages - they're XML constructs which are referenced by a name and store text, images and file references. Once an entity has been defined, XML authors may call it by its name at different places within an XML document, and the XML parser will replace the entity name with its actual value.

XML entities come in particularly handy if you have a piece of text which recurs at different places within a document - examples would be a name, an email address or a standard header or footer. By defining an entity to hold this recurring data, XML allows document authors to make global alterations to a document by changing a single value.

An entity declaration typically looks like this:

<!ENTITY entityName entityValue>
Consider the following XML document,

<?xml version="1.0"?> <article> <title>The Fundamentals Of DTD Design)</title> <abstract>A discussion of DTD syntax and construction</abstract> <body> İright; Article body goes here İright; </body> </article>
and then take a look at its DTD, which sets up the entity.

<!-- element declarations --> <!ELEMENT abstract (#PCDATA)> <!ELEMENT article (title, abstract, body)> <!ELEMENT body (#PCDATA)> <!ELEMENT title (#PCDATA)> <!-- entity declarations --> <!ENTITY copyright "This material copyright Melonfire, 2001. All rights reserved.">
Entity declarations can contain XML markup in addition to ordinary text - the following is a perfectly valid entity declaration:

<!ENTITY copyright "This material copyright <link>Melonfire</link>, <publication_year>2001</publication_year>. All rights reserved.">
Entities may be "nested"; one entity can reference another. Consider the following entity declaration, which illustrates this rather novel concept.

<!ENTITY company "Melonfire"> <!ENTITY year "2001"> <!ENTITY copyright "This material copyright &company;, &year;. All rights reserved.">
Note, however, that an entity cannot reference itself, either directly or indirectly, as this would result in an infinite loop (most parsers will warn you about this.) And now that I've said it, I just know that you're going to try it out to see how much damage it causes.

>>> More XML Articles          >>> More By Vikram Vaswani, (c) Melonfire

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Google Docs and Xpath Data Functions
- Flex Array Collection Sort and Filtering
- The Flex Tree Control
- Flex List Controls
- Working with Flex and Datagrids
- How to Set Up Podcasting and Vodcasting
- Creating an RSS Reader Application
- Building an RSS File
- An Introduction to XUL Part 6
- An Introduction to XUL Part 5
- An Introduction to XUL Part 4
- An Introduction to XUL Part 3
- An Introduction to XUL Part 2
- An Introduction to XUL Part 1
- XML Matters: Practical XML Data Design and M...

Developer Shed Affiliates


Dev Shed Tutorial Topics: