XML Entities

These are placeholders for code and data that can be expanded within a XML document. There are several types of entities

  • External

    • Used inside a XML file but the contents are referenced from an external file or URL.

      • <!DOCTYPE note [
        <!ENTITY ext SYSTEM "http://example.com/external.dtd">
        ]>
        <note>
                <info>&ext;</info>
        </note>
  • Internal

    • Used within a XML document to define content that can be used multiple times.

      • <!DOCTYPE note [
        <!ENTITY inf "This is a test.">
        ]>
        <note>
                <info>&inf;</info>
        </note>
  • Parameter

    • special types of entities used within DTDs to define reusable structures or to include external DTD subsets. Useful to maintain large scale XML applications

      • <!DOCTYPE note [
        <!ENTITY % common "CDATA">
        <!ELEMENT name (%common;)>
        ]>
        <note>
                <name>John Doe</name>
        </note>
  • General

    • can be declared either internally or externally. They are used to define substitutions that can be used within the body of the XML document.

      • <!DOCTYPE note [
        <!ENTITY author "John Doe">
        ]>
        <note>
                <writer>&author;</writer>
        </note>
  • Character

    • Used for special or reserved characters that cannot be used directly in XML documents.

      • <note>
                <text>Use &lt; to represent a less-than symbol.</text>
        </note>
      • Example:

        • &lt; for the less-than symbol (<)

        • &gt; for the greater-than symbol (>)

        • &amp; for the ampersand (&)

Last updated