Re: Example for Entity and EntityReferences

> Could any one point me to a detailed Example on using Entity and
> EntityReferences.

Entity nodes correspond to General Entity declarations in the DTD. If it's
a parsed or literal entity, the children of the Entity node will correspond
to its value. If it's an Unparsed Entity, retrieving its value is outside
the scope of the DOM.

     <!ENTITY Pub-Status "This is a pre-release of the specification.">

     becomes an Entity node with one Text child containing
     the string "This is a pre-release of the specification."

There's no public API for creating Entity nodes (we'll address that in DOM
Level 3), so they will only exist if (a) you parse a document whose DTD
defines them or (b) you use a nonstandard mechanism to create them.
Similarly, there's no API for editing existing Entity nodes.


EntityReference nodes correspond to Entity References in the instance
document. If there's an Entity node with the same name, the children of an
EntityReference node will be read-only clones of the children of that
Entity.

     &Pub-Status;

     corresponds to an EntityReference node with one Text child containing
     the string "This is a pre-release of the specification."

HOWEVER: Parsers are also allowed to "flatten" references by leaving out
the EntityReference node, and just inserting the read-only entity value at
that point in the document. Sometimes this is more convenient for
applications, sometimes less convenient, depending on whether they need to
know that these nodes came from an entity, so the DOM permits both
approaches. The user-code equivalent would be to manually clone the
Entity's children and insert them at the appropriate place.


Does that help, or have I answered the wrong question?

______________________________________
Joe Kesselman  / IBM Research

Received on Thursday, 27 April 2000 19:06:05 UTC