XML Entity
An entity is a symbolic representation of information. What does that mean? Well, let's imagine for a moment that we want to create an introduction that is included in every single memo that we write. It would be monotonous to have to type out a three sentence introduction for every letter, but not to worry! XML entities can help us out.With symbolic representation of information, a lot of text, such as, "Hello my name is Tizag.com and I am an artificial intelligence that teaches the general public how to program in web languages for free," can be represented by an entity symbol.
Entity Syntax
You may have used entities in the past. The format of an entity in XML is an ampersand (&), followed by the name of the symbol, and concluded with a semicolon.- Generic Entity - &name;
- © = ©
- < = <
- & = &
- " = "
Creating an XML Entity
An entity must be created in the Document Type Definition (DTD). Once you know where to place the entity, the rest is easy. Here is the syntax for creating your own XML entities.- <!ENTITY entityName "The text you want to appear when the entity is used">
XML Code:
<!ENTITY intro "Hello my name is Tizag.com and I am an artificial intelligence that teaches the general public how to program in web languages for free">
Using Your Entity
After the entity has been created in the DTD, it can then be referenced. An example email XML document that uses such an entity would look like:XML Code:
<!ENTITY intro "Hello my name is Tizag.com and I am an artificial intelligence that teaches the general public how to program in web languages for free"> <email> <to>A. Nony Mouse</to> <body>&intro;</body> </email>
- Use something a lot. If you have a default introduction, signature, or something else that is commonly used, you should use an entity.
- Change something often. If you have a relatively static document that has one or two pieces of frequently-changing information that are used throughout the document, replace them with entities. You only need to change the value of the entity to change hundreds or maybe even thousands of references that are in your XML document.
- Are using complex ASCII characters that don't occur on your keyboard: © and ® are easy when you use entities.
0 comments:
Post a Comment