XML — Entity Reference
Predefined Entities
| Entity | Character | Description |
|---|---|---|
| < | < | Less than |
| > | > | Greater than |
| & | & | Ampersand |
| " | " | Double quote |
| ' | ' | Apostrophe |
Using Entities
<text>Price: 5 < 10 & 10 > 5</text>
Custom Entities
<!DOCTYPE note [
<!ENTITY copyright "© 2025 Example Inc.">
<!ENTITY company "ACME Corp">
]>
<note>
<text>This is ©right; by &company;</text>
</note>
Numeric Character References
<!-- Decimal -->
A <!-- A -->
© <!-- © -->
<!-- Hexadecimal -->
A <!-- A -->
© <!-- © -->
CDATA Section
For content with many special characters:
<script>
<![CDATA[
if (x < 10 && y > 5) {
alert("Hello <world>");
}
]]>
</script>
Entity Types
| Type | Scope |
|---|---|
| Internal | Defined in DTD |
| External | Referenced file |
| Parameter | Used in DTD |
| General | Used in document |
Best Practices
- Use predefined entities for special characters
- Use CDATA for code blocks
- Define custom entities for reuse
- Avoid external entities (security risk)
Mini Practice
- Use all predefined entities
- Create a custom entity
- Use numeric character references
- 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.