W3C home > Mailing lists > Public > www-dom@w3.org > April to June 2002

Re: createTextNode and special characters

From: Joseph Kesselman <keshlam@us.ibm.com>
Date: Tue, 28 May 2002 14:53:54 -0400
To: Immanuel Normann <normann@dfki.de>
Cc: www-dom@w3.org
Message-ID: <OFD11CA7BA.4F77FBB1-ON85256BC7.0066E12C@pok.ibm.com>

This is correct operation.

The DOM API assumes you're already talking about the content of the
document, not its XML syntactic representation. If you create a text node
containing the & character using the DOM calls, it's assumed you really
mean the & character, _NOT_ the & introducing a numeric character reference
or entity reference.

To insert a special character, simply insert the character directly into
the text string, in its UTF-16 form. I don't know enough Javascript to tell
you how to code that, but it should be possible.

To insert an entity reference, you want to use the createEntityReference
call rather than the createTextNode call.
 var t = document.createEntityReference('forall');
This may not work if your  DOM doesn't know which DTD you're using and/or
hasn't retained a list of which entities are being defined (and thus
doesn't know what "forall" represents).

>How do I ask my parser to retain Entity Reference?
>How do I tell the DOM generator to "expand" entity references?

See the docs for your parser.

Joe Kesselman  / IBM Research
Received on Tuesday, 28 May 2002 14:55:20 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:10 UTC