</>
Skip to content
XML lessons (29/29)

XML — Entity Reference

Predefined Entities

EntityCharacterDescription
<<Less than
>>Greater than
&&Ampersand
""Double quote
''Apostrophe

Using Entities

<text>Price: 5 &lt; 10 &amp; 10 &gt; 5</text>

Custom Entities

<!DOCTYPE note [
    <!ENTITY copyright "© 2025 Example Inc.">
    <!ENTITY company "ACME Corp">
]>
<note>
    <text>This is &copyright; by &company;</text>
</note>

Numeric Character References

<!-- Decimal -->
&#65;    <!-- A -->
&#169;   <!-- © -->

<!-- Hexadecimal -->
&#x41;   <!-- A -->
&#xA9;   <!-- © -->

CDATA Section

For content with many special characters:

<script>
<![CDATA[
    if (x < 10 && y > 5) {
        alert("Hello <world>");
    }
]]>
</script>

Entity Types

TypeScope
InternalDefined in DTD
ExternalReferenced file
ParameterUsed in DTD
GeneralUsed in document

Best Practices

  1. Use predefined entities for special characters
  2. Use CDATA for code blocks
  3. Define custom entities for reuse
  4. Avoid external entities (security risk)

Mini Practice

  1. Use all predefined entities
  2. Create a custom entity
  3. Use numeric character references
  4. Write CDATA sections

Up Next

Congratulations! You've completed the XML course. Continue exploring advanced XML topics and applications.

Related Topics

Frequently Asked Questions about Entity Reference

What is Entity Reference in XML?

Entity Reference is a fundamental concept in XML. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Entity Reference?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Entity Reference.

Why is Entity Reference important in XML?

Entity Reference is essential for XML development. Understanding this concept will help you write better code and solve real-world problems more effectively.