Node.data trims start/end whitespace
Emmanouil Batsis
manos_lists at geekologue.com
Sun Jun 12 00:45:52 BST 2005
In other words, konq's concatenation of the text nodes found in the following
doc:
<root><element>this has <![CDATA[ CDATA ]]></element> and some more
text</root>
is "this hasCDATAand some more text" while it should be "this has CDATA and
some more text". I'm using KDE 3.4.
Manos
On Tuesday 24 May 2005 23:43, Emmanouil Batsis wrote:
> It seems node.data for nodeTypes Node.TEXT_NODE nodeType and
> Node.CDATA_SECTION_NODE missbehaves; it does not return whitespace when
> that is at the start or end of the given node text value. For example the
> following function [2] will return "hfyrhy5hyfgfdsgf" instead of "hfyrhy 5h
> yfgfdsgf" if fed with the XML tree below. Can someone please confirm
> whether this is a bug for me to submit?
>
> [1] <root><element>hfyrhy <![CDATA[5h ]]>yf</element>gfdsgf</root>
>
> // [2]
>
> Sarissa.getText = function(oNode, deep){
> var s = "";
> var nodes = oNode.childNodes;
> for(var i=0; i < nodes.length; i++){
> var node = nodes[i];
> var nodeType = node.nodeType;
> if(nodeType == Node.TEXT_NODE || nodeType ==
> Node.CDATA_SECTION_NODE){ alert("node.data: '"+node.data+"'");
> s += node.data;
> }
> else if(deep == true
> && (nodeType == Node.ELEMENT_NODE
>
> || nodeType == Node.DOCUMENT_NODE
> || nodeType == Node.DOCUMENT_FRAGMENT_NODE)){
>
> s += Sarissa.getText(node, true);
> };
> };
> return s;
> };
More information about the kfm-devel
mailing list