Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: IE and Mozilla recognize CDATA nodetype differently

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 2/4/2006 5:01:00 PM

aziz.hammadi@g... wrote:


> I am trying to access an HTML code stored as CDATA section in the xml
> file listed bellow:
> 
> <?xml version="1.0"?>
> <results count="5">
> <![CDATA[
>     <table><tr><td>Hello World</td></tr></table>
> ]]>
> </results>
> 
> The xml tree is the responseXML part of an XmlHttpRequest and is stored
> in a the javascript object xmldoc. While trying to test the node type
> of the children of the "results"-Element  I got different results with
> IE and Mozilla:
> 
> xmldoc.getElementsByTagName("results")[0].childNodes[0].nodeType -->
> MN=>TEXT,IE =>CDATA
> 
> xmldoc.getElementsByTagName("results")[0].childNodes[1].nodeType -->
> MN=>CDATA,IE =>NULL

IE gives you a script error that childNodes[1] is null, right?
The issue is known, Mozilla includes all white space in the DOM as text 
nodes while IE uses MSXML as the XML parser and that only does that with 
a special setting preserveWhiteSpace set to true.
If you index childNodes then you need to check for null values first and 
then for nodeType to make sure that you have the node you are looking 
for if you script against different DOM implementations.



-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent