How to create Entity in XML

In this article I have describe about create XML Entity.
  • 1874

How to use entity in XML

An entity is created XML syntax and created by the Document Type Definition (DTD). If we have define a entity in DTD then we use XML documents.

Syntax of defining XML Entity code

  • When we define entity then we use <!ENTITY entity Name or definition name.
  •  Entity name is define the name of entity and definition is define the definition of entity.  
<!ENTITY intro "Hello I am MCN Solution">

The name of the entity is intro, and definition of entity is "Hello I am MCN Solution".

Using your entity

When we use entity, we also write entity in DTD, and represent by the &entity-name.

Example:

<?xml version="1.0"?>

<!DOCTYPE tutorials [

  <!ENTITY footer "Hello I am MCN Solution!">

]>

<tutorials>

  <tutorial>

    <name>XML Tutorial</name>

    <url>http://www.dotnetheaven.com/article/xml</url>

    <footer>&footer;</footer>

  </tutorial>

  <tutorial>

    <name>HTML Tutorial</name>

    <url>http://http://www.dotnetheaven.com/article/xml</url>

    <footer>&footer;</footer>

  </tutorial>

</tutorials>

 

Code Explanation

  • In this example we want to repeat some text "Hello I am MCN Solution" in our output.

  • Entity "footer" is created &footer to represent the text show for every time.

  • If you want to change the text then we change it in one place-the definition.

  • &footer use to print the message for any position.

You may also want to read these related articles :

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2019 DotNetHeaven. All rights reserved.