Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,

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

Using below code
JavaScript
if (window.DOMParser)
       xmlDoc = domParser.parseFromString(xmltext, "text/xml");
   else //IE
       xmlDoc.loadXML(strXML);

  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
Comments
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.
—SA
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)
</pre>
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);
else
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?
—SA
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
Sergey Alexandrovich Kryukov 1-May-13 10:26am    
Thanks goodness; now I understand it. Sorry, by some reason I thought it was external code. Looks weird...
—SA

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900