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:

  • & 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 to specify the correct character code in the encoding that 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 modify the example document at the beginning of this chapter that uses those entity references—this time I define 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>
				

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset