Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts

    document.createTextNode with entities

    I don't know if this is specific to working in the XML DOM, or generally with this method, but when I do this

    document.createTextNode('»');

    and append it to a node, it outputs the text "»" rather than the "╗" symbol. I've also tried » and » but they all just output the literal text

    Last edited by brothercake; 05-01-2003 at 01:04 AM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeň, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Nope, it's not specific to the XML (Core) DOM - a TextNode can only contain pure text. If you want to create an entity, you have to use Document.createEntityReference which to my knowledge isn't implemented anywhere (or at least wasn't working even in moz last time I tried to use it).

    It takes a DOMString with UTF-16 characters, so I guess you can use a JavaScript string with U+00bb to get your result. ("\u00bb")
    Last edited by liorean; 05-01-2003 at 01:29 AM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No it didn't work in moz - it returned a component failure.

    But your other solution worked; nice idea
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeň, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Only knew about that due to the fact I've tried to do what you wanted to do before... I doubt I'd found it from reading the specs.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Posts
    185
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Entity references are necessary in the HTML or XML markup. For example, &lt; in a text file tells a parser that the '<' character is part of the data, not the start of a new tag.

    But once a document is parsed into a DOM representation, you no longer need to distiguish between the markup and the data. Programming object represent nodes, rather than syntactic strings of text. The DOM doesn't need entity references because there's no mistaking between what's structure and what's data. That's why it gives you the literal text.

    How you define characters within the DOM depends on the particular DOM API. liorean's suggestion works in JavaScript because that language uses the \u escape sequence in string literals to define arbitrary Unicode characters. I think C and Java use that too, but other languages might use other methods. It's all dependent on the language of the DOM implementation, not on the DOM or XML standards.

    I hadn't heard of document.createEntityReference before but I suspect it's a convenience function that will maps an entity reference to a native character code for you. That would be a nice alternative to looking up the codes.

  • #6
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeň, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Entities are a bit more than that. An entity in HTML is usually a single character - it needn't be. And entity can be a strings of longer content, composed of other entities and/or characters. They are defined by the DTD, though, and that's where the problem lies: our browsers are not validating XML parsers, even if expat and msxml have that ability - they don't parse the DTD, they merely checks if one they recognise exists, and use that one.
    In other words, they don't "get" entities. They resolve the standard html set of them, but they don't let the user define new ones.

    An entity reference is what it sounds like, a reference to an entity - the entity itself is what tells us what content it's to be replaced with. (Look on entities as the declaration of a variable - and entity references as the usage of that variable. It's the closest analogue that I can think of.)
    Last edited by liorean; 05-02-2003 at 12:38 PM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #7
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Originally posted by liorean
    In other words, they don't "get" entities. They resolve the standard html set of them, but they don't let the user define new ones.
    You almost speak truth. Mozilla is not a validating XML parser, very true. However, you can define entities to use within a DTD. It also understands MathML entities given the correct doctype.

    Lame example I did for an entirely other reason (but is chockful of my &mathml; entity for shortcut namespacing, and of course the MathML entities):
    http://www.jasonkarldavis.com/script...ed/example.xml

  • #8
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeň, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Hmm, I doubt you are right about that - in the same way moz has a knowledge of the XHTML namespace, it has a knowledge of the MathML namespace. The knowledge of the namespaces means they have either the rules of that DTD hardcoded, or they has a copy of it that they parse when encountering that DTD declaration. This means they also have a knowledge of the entities used in that namespace.

    Try doing the same, but use a custom namespace that moz doesn't have any knowledge of - you'd find that moz doesn't handle them. (moz might not parse custom DTDs, but it does parse the <!ENTITY> entries in the DTD declaration)



    (I've not done any testing on this - so you may be right...)
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #9
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    I never said Mozilla understood DTD. I said given the correct DTD, it knows MathML entities. You are correct, it is hardcoded, but you were debating something I had never said.

    I was just saying that it knew about defined entities inside an inline doctype basically.

  • #10
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeň, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Oh, I just misinterpreted this, then:
    Originally posted by jkd
    However, you can define entities to use within a DTD.
    You meant Document Type Declaration (the SGML construct that references the definition, whether embedded or included), not as I thought Document Type Definiton (the actual definition, most often included through a .dtd file).

    W3C warns for the problems with the abbreviation DTD and states that you should use the wording "DTD declaration" or "doctype declaration" if you speak of the SGML construct and not the actual definition.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #11
    Regular Coder
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I know this is nearly 3 years late, but you helped me figure out this solution: http://www.codingforums.com/showthread.php?t=80593


  •  

    LinkBacks (?)

    1. 02-25-2014, 11:06 PM

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •