Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - IE and Mozilla recognize CDATA nodetype differently [Thread Next] Re: IE and Mozilla recognize CDATA nodetype differentlyTo: 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/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
