Entities
Added 26 Jul 2008
An XML document is made up of data. XML documents can get data and declarations from many different sources, including CGI scripts, databases, and other XML files. Each of these items is an entity.
The file you use to write your XML declaration, document type declaration, and root element is called the document entity. In my example on the previous page, these would be:
- XML declaration
- document type declaration (in this case the entire DTD)
]> - root element
...
Entities can be external to your XML document, like a stylesheet or XSL document, or internal like something you define. The most common internal entity is a general entity. This is used as an abbreviation for commonly used text, or text that is difficult to type.
To define an internal general entity, you use the tag in your
DTD:
name "text to be replaced">
For example: writing out "Jennifer Kyrnin, About Web Design Guide" is a bit long, but I can create an entity to add that into my XML documents with just 4 characters: aand every time I type &jkk; in an XML document with that DTD, it will expand to read "Jennifer Kyrnin, About Web Design Guide".
To define an external entity, you create a very similar tag in your DTD, but you include the word "SYSTEM" so that the parser knows that this is an external entity.