Character Entity References & DOM

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • User Axes Dean Eyed

    Character Entity References & DOM


    The following statement does not yield what I expect it to:

    var txtNode = document.create TextNode("ESI&m inus;");

    txtNode holds a value of "ESI− " instead of "ESI-" where '-' is the
    character entity reference for the minus sign, that I expect.

    I have tried other variations. I am working with Mozilla and IE because I
    want to make NO use of extensions/browser-dependent code, and both (try to)
    implement the DOM to varying degrees.

    Searches of keyword sets:

    createTextNode "character entity" HTML

    and the permutations have not been helpful.

    Does anyone know the secret?
  • Michael Winter

    #2
    Re: Character Entity References & DOM

    On Wed, 06 Oct 2004 18:01:51 GMT, User Axes Dean Eyed
    <ResistanceFuti le@Assimilated. B.org> wrote:
    [color=blue]
    > The following statement does not yield what I expect it to:
    >
    > var txtNode = document.create TextNode("ESI&m inus;");
    >
    > txtNode holds a value of "ESI&minus; " instead of "ESI-" where '-' is the
    > character entity reference for the minus sign, that I expect.[/color]

    This is discussed in the Specification:

    <URL:http://www.w3.org/TR/DOM-Level-2-Core/introduction.ht ml#ID-E7C30824>

    As the extended intefaces mentioned in that section are directed at XML
    documents, I don't think it's possible to include an entity reference in
    the way you want. Your best bet is to look up the numeric values of the
    entities (<URL:http://www.w3.org/TR/html4/sgml/entities.html>) and use
    JavaScript string escape sequences. Numeric codes below 255 can be
    specifed in hexadecimal using \xNN. Other characters must use the Unicode
    hexadecimal sequence, \uNNNN. These are provided in the reference above
    within the entity comments (look for U+NNNN). Your code above would be:

    var txtNode = document.create TextNode("ESI\u 2212");

    [snip]

    Hope that helps,
    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.

    Comment

    Working...