Ben Griffin wrote:
Is it correct that createTextNode should XML Encode the DOMString passed to it?
I'm going to assume by "XML Encode" you mean to escape any markup characters. If that's the case, the answer is no.

To me, w3 implies that the text should be parsed as if it is xml already.
http://www.w3.org/TR/DOM-Level-2-Core/core.html
Text  createTextNode(in DOMString data);
"The Text interface inherits from CharacterData and represents the textual content (termed character data in XML) of an Element or Attr. If there is no markup inside an element's content, the text is contained in a single object implementing the Text interface that is the only child of the element. If there is markup, it is parsed into the information items (elements, comments, etc.) and Text nodes that form the list of children of the element."
The value of a text node is _not_ markup, so markup characters will not be escaped.



DomDocument says nothing about this:
    /**
     * Creates a <code>DOMText</code> node given the specified string.
     * @param data The data for the node.
     * @return The new <code>DOMText</code> object.
     * @since DOM Level 1
     */
    virtual DOMText         *createTextNode(const XMLCh *data) = 0;

XMLCh* newval = X("Mum &amp; Dad");
You are creating a string with 13 characters.

DOMText* vt = doc->createTextNode(newval);

vt now contains "Mum &amp;amp; Dad"
When you say "vt now contains" that string, how are you checking that? I would expect this to occur if you serialized the document, but not if you were viewing it in a debugger, or through a binary dump.

How may I create a TextNode that knows that the XMLCh* is already xml-encoded?
You can't.


This is relevant, as I may have dynamically extracted the XMLCh* from existing xml.
I don't know what you mean by this statement. Character data in a text node is not markup, it's character data. As long as you are copying data from one text node to another, there's nothing special you need to do.

What you cannot do is put markup in a text node and expect that it will be treated as markup.

Dave

Reply via email to