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: Consider the following XML document, and then take a look at its DTD, which sets up the entity. Entity declarations can contain XML markup in addition to ordinary text - the following is a perfectly valid entity declaration: Entities may be "nested"; one entity can reference another. Consider the following entity declaration, which illustrates this rather novel concept. 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.
blog comments powered by Disqus |