Click here to Skip to main content
13,054,329 members (125,571 online)
Rate this:
Please Sign up or sign in to vote.

I am creating CDATA section as a child node. I have seen below mentioned behavior with Firefox, IE8,9, and 10

Using below code
if (window.DOMParser)
       xmlDoc = domParser.parseFromString(xmltext, "text/xml");
   else //IE
  var elem= xmlDoc.createElement("a");
 elem.appendChild(xmlDoc.createCDATASection("some value"))

With IE,8,9, and firefox if i pass empty string , it still creates CDATA section with nothing in bracket like below
<a sd="7493" re="453" yh="67"><![CDATA[]] > </a>

But with IE 10 , it does not create CDATA if no value is passed in createCDATASection. Also with IE10, it passes window.DomParser check. Also if make IE10 also load xml like xmlDoc.loadXML(strXML); then it does create CDATA for IE10 as well.

Can anyone explain why such kind a behavior
Posted 30-Apr-13 10:19am
Sergey Alexandrovich Kryukov 30-Apr-13 17:20pm
This is illogical question. You cannot say that the code created empty CDATA "with IE 10". The code generating XML does not depends on the browser you use to see the result. Take a text editor and see what's generated. Check up your observation, and them formulate the problem correctly, if you still see it.
devcode007 30-Apr-13 17:46pm
I am saying IE 10 does not created Child node for element a i.e with IE 9 same code creates

(less than)a sd="7493" re="453" yh="67"> [CDATA[]] <End Tag>a> <End Tag> but with IE 10 same code creates
(less than)a sd="7493" re="453" yh="67"> <End Tag>a> <End Tag> (No Child node)
The only difference in code is creating xmlDoc.
IE 9 uses : xmlDoc.loadXML(xmltext);
IE 10 uses: xmlDoc = domParser.parseFromString(xmltext, "text/xml");

I confirmed this behavior by extracting XML and observing all the nodes created.
Below is the code used to retrieve xml
Var tempxml;
if (window.DOMParser)
tempxml = new XMLSerializer().serializeToString(xmlDoc);
tempxml = return xmlDoc.xml;
Sergey Alexandrovich Kryukov 30-Apr-13 17:53pm
IE cannot be used for creating of any nodes (I'm not talking about JavaScrip running under IE). IE does not create anything at all. What are you talking about?
devcode007 1-May-13 9:40am
I am talking about javascript running under IE10 vs running under IE9. When i say IE10 created I meant running this given code under IE 10 browser
Thanks goodness; now I understand it. Sorry, by some reason I thought it was external code. Looks weird...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100