Predefined General Entity References

As we already know, there are five predefined entity references in XML, and they stand for characters that can be interpreted as markup or other control characters . Here they are:

  • & becomes the & character.

  • ' becomes the ' character.

  • > becomes the > character.

  • &lt; becomes the < character.

  • &quot; becomes the " character.

It turns out that you can create entity references for individual characters yourself in XML. All you have to do is specify the correct character code in the encoding you're using. For example, in the UTF-8 encoding, the character code for @ is #64 (where the # indicates that this value is in hexadecimal), so you can define an entity named, say, at_new so that references to at_new will be replaced by @ when parsed. Here's how that entity would look:

 <!ENTITY at_new "&#64;"> 

In fact, you can even define the predefined entity references yourself, in case you run across an XML processor that doesn't understand them. Here's how I modified the example document at the beginning of this chapter that uses those entity referencesthis time defining the entities myself :

 <?xml version = "1.0" standalone="yes"?>  <!DOCTYPE TEXT [ <!ENTITY amp_new "&#38;#38;"> <!ENTITY apos_new "&#39;"> <!ENTITY gt_new "&#62;"> <!ENTITY lt_new "&#38;#60;"> <!ENTITY quot_new "&#34;"> ]> <TEXT>     This text about the &quot_new;S&amp_new;O Railroad&quot_new;     is the &lt_new;TEXT&gt_new; element&apos_new;s content. </TEXT> 


Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net