In this tutorial you will learn about the XML Entity and its application with practical example.
We are familiar to HTML Entities. HTML Entity is symbolic representation of the information.
Lest take look at some HTML Entity –
- © = ©
- < = <
- & = &
- " = “
XML also supports the entity , An entity in XML is represented using an ampersand (&), followed by the name of the symbol, and ends with a semicolon.
Example:
1 |
&name; |
Creating an XML Entity
We can create our own custom entity, by defining it in DTD. Once we defined it we can use it in our XML document.
Syntax:
Here is syntax to define entity in DTD
1 |
<!ENTITY entityName "Replacement Text"> |
Using Your Custom Entity
Once we have created XML entity we can use it in following way, let take look in below example code
1 2 3 4 |
<!ENTITY welcome "Welcome to W3school.in"> <site> <message>&welcome; A tutorial site</message> </site> |