Entity (W3C DOM Core object)

Spec
Version Depr. Parent
DOM1 No Node
Browser support (more…)
IE5.5+ FF3 SA3 OP9+
Buggy None None Partial

Example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
[
  <!ENTITY hawk "MC Hawking">
  <!ENTITY snoop "Snoop Doggy Dogg">
]>

The example above shows an XHTML 1.0 Strict DocumentType with additional entities defined in the internalSubset. We can get a reference to all the entities declared in the DTD using the entities collection, which itself is a property of the doctype:

var entities = document.doctype.entities;

And then retrieve individual items from that collection using the getNamedItem method:

entities.getNamedItem('sitepoint')

The entities collection should include both internal and external entities, however in practise this varies by browser (see the Compatibility notes below for details).

Description

The Entity interface inherits from Node, and represents an expanded entity, ie. the entity itself (eg. &), not the entity reference (eg. amp); entity references are controlled by the EntityReference interface.

The DOM does not require an implementation to expand external entities, hence the replacement value of an entity reference may not be available; if it is available it will appear in the childNodes collection of the EntityReference.

Conversely, an implementation may choose to expand all entities before building the DOM tree, in which case there will be no EntityReference nodes in the document at all, only Entity nodes.

Entity nodes and their descendents are read-only, and can only be modified at the EntityReference level.

An Entity node can have Element, ProcessingInstruction, Comment, Text, CDATASection and EntityReference nodes as children.

Compatibility

Internet Explorer Firefox Safari Opera
5.5 6.0 7.0 1.5 2.0 3.0 1.3 2.0 3.0 9.0 9.5
Buggy Buggy Buggy None None None None None None Partial Partial

Only Internet Explorer in XML and Opera in XHTML mode or XML1 provide data for the entities collection; in Firefox, Safari 1.3 and 2 in XHTML mode or XML, and Safari 3 the collection is null; in other environments the doctype itself is null or undefined (see DocumentType for details).

In Internet Explorer in XML this collection only includes internal entities (those defined in a doctype's internal subset); external entities are not included. Furthermore, it doesn't support associative array syntax for retrieving members by name (eg. entities['hawk']); it only supports reference by index (eg. entities[0]) or using the getNamedItem method of NamedNodeMap (eg. entities.getNamedItem('hawk')).

In this Section

Footnotes

1 On XHTML pages served as application/xhtml+xml.

User-contributed notes

There are no comments yet.

Related Products