web analytics

Predefined entities in XML documents

Options

codeling 1595 - 6639
@2016-01-09 17:51:58

The special characters for quote ("), apostrophe ('), less-than (<), greater-than (>), and ampersand (&) are used for punctuation in XML, and are represented with predefined entities: &quot;, &apos;, &lt;, &gt;, and &amp;. Notice that the semicolon is part of the entity.You cannot use "<" or "&" in attributes or elements, as the following series of examples demonstrates.

<?xml version="1.0" encoding="utf-8"?>
<root>
    <text>
        These are predefine entities in xml: &quot; &lt; &gt; &amp; &apos;
    </text>
</root>

HTML has many other predefined entities, for example &nbsp; for a "non breaking space" or &copy; for "copyright symbol":

http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

In order to use these  entities, users can either use the corresponding Unicode hexadecimal value, or can actually define them using a DOCTYPE declaration.  

For example, to define &nbsp; and &copy; use:

<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE Html [

<!ENTITY nbsp "&#x00A0;">

<!ENTITY copy "&#169;">

]>

<root>

    <text>

        This text is separated by non breaking spaces: Mary&nbsp;had&nbsp;a&nbsp;little&nbsp;lamb.

   </text>

    <text>

        This is the copyright symbol : &copy; 

    </text>

</root>

The same result would be obtained by using the hexadecimal notation:

<?xml version="1.0" encoding="utf-8"?>

<root>

    <text>

        This text is separated by non breaking spaces: Mary&#x00A0;had&#x00A0;a&#x00A0;little&#x00A0;lamb.

   </text>

    <text>

        This is the copyright symbol : &#x00A9;

    </text>

</root>

@2016-01-26 11:38:03

If you need to define an attribute that contains single or double quotes, you can use one style of quote inside the other. If you need both single and double quotes in an attribute, use the predefined entities &quot; for double quotes and use &apos; for single quotes:

<book title="You're Hero" />

<book title='You&apos;re Hero' />
@2019-06-11 15:10:35

Trademark & registered trademark  & copyright symbol codes

Sign Name code Decimal code Hex code Description
&trade; &#8482; &#x2122; trademark symbol
® &reg; &#174; &#x00AE; registered trademark symbol
© &copy; &#169; &#x00A9; copyright symbol

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com