XML ENTITY Declaration
You can declare your own XML ENTITY. XML give you control to make your own ENTITY. You can define/declare the entity in Document DTD (Document Type Definition) section. Once you create ENTITY, you can ready to use that entity in your XML document.
XML ENTITY use to represent specific character that are difficult to write in standard keyboard. You can access defined entity in several times.
XML 1.0 standard define five different entities. Following table represent five XML predefined entities lists.
Character | Entities | Unicode | Description | Standard |
---|---|---|---|---|
" | " | U+0022 (34) | Double quotation | XML 1.0 |
' | ' | U+0027 (39) | Apostrophe (Single quotation) | XML 1.0 |
& | ' | U+0026 (38) | ampersand sign | XML 1.0 |
< | < | U+003C (60) | less than | XML 1.0 |
> | > | U+003E (62) | greater than | XML 1.0 |
Entities start with ampersand (&) sign and ending with semi colon(;).
Entity Declaration
Define entity using <!ENTITY>
declaration element.
<!ENTITY name definition>
Syntax Description
name - define the entity name
definition - define specific code snippets that you want to actually represent.
How to access entities
We define following 3 entities that will use in XML document.
<!ENTITY company "Odoo (formally OpenERP)">
<!ENTITY street "Tower-1, Infocity">
<!ENTITY ph "000-478-1414">
Following example create entities and use in XML document.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE employee [
<!ENTITY company "Odoo (formally OpenERP)">
<!ENTITY street "Tower-1, Infocity">
<!ENTITY ph "000-478-1414">
]>
<employee>
<emp_info id="1">
<name>
<first_name>Opal</first_name>
<middle_name>Venue</middle_name>
<last_name>Kole</last_name>
</name>
<contact_info>
<company_info>
<comp_name>&company;</comp_name>
<comp_location>
<street>&street;</street>
<city>GH</city>
<phone>&ph;</phone>
</comp_location>
<designation>Junior Engineer</designation>
</company_info>
<phone>000-987-4745</phone>
<email>[email protected]</email>
</contact_info>
</emp_info>
</employee>