Re: IE and Mozilla recognize CDATA nodetype differently
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: IE and Mozilla recognize CDATA nodetype differently

From: Aziz <rass.elma@googlemail.com>
Date: Sun Feb 05 2006 - 17:22:55 CET

Thanks for the help. I have modified my PHP server side code to provide
the xml response as a string with no \n or \r.

> To clarify it isn't the line break per se but any white space between tags
> generates another child. e.e. <parent> <child>First Born</child>.... The
> space between <parent> and <child> will give you that extra child node in
> the XML parser.
>
> "Digital" <report@spam.com> wrote in message
> news:tv5Ff.89242$Dk.27886@tornado.rdc-kc.rr.com...
> > Aziz -
> >
> > You need to keep in mind that Mozilla has a very rough time conforming to
> > standards. Especially when dealing with XML. You will need to run a
> > "fixer utility" on your XML data before Mozilla can understand it. Here
> > is the problem:
> >
> > <parent>
> > <child1/>
> > <child2/>
> > <child3/>
> > </parent>
> >
> > What you have there is a parent with 3 children to every XML parser in the
> > world but Mozilla's. In Mozilla you have a parent with 7 children.
> > Mozilla treats each line break as a child. In order to combat this you
> > need to loop through every child and if the nodeType = 3 and the nodeName
> > = '#text' and the number of childNodes > 1 then you know that what you
> > have there is a fake child and you can remove that node.
> >
> > ~Digital~
> >
> > "Aziz" <rass.elma@googlemail.com> wrote in message
> > news:1139068462.499811.35130@g44g2000cwa.googlegroups.com...
> >> Hi Folks
> >> 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
> >>
> >> I added a non empty text node to the result element:
> >> <results count="5">
> >> blalba text
> >> <![CDATA[...
> >>
> >> Now I get this:
> >> xmldoc.getElementsByTagName("results")[0].childNodes[0].nodeType -->
> >> MN=>TEXT,IE =>TEXT
> >> xmldoc.getElementsByTagName("results")[0].childNodes[1].nodeType -->
> >> MN=>CDATA,IE =>CDATA
> >>
> >> Does someone have an explanation for this behaviour?
> >>
> >> I am using Mozilla 1.5 and IE 6
> >>
> >> Cheers,
> >> Aziz
> >>
> >
> >
Received on Tue Feb 7 21:35:14 2006