Kung Fu Kung Fu

Fujian White Crane Kung Fu

Zope Zope

What I have and am doing with Zope

Photos Photos

Photoalbum, both old and new.

Receptsamlingen Receptsamlingen

In Swedish only. About my "Collection of Recipes" website.

Contact me Contact me

My contact details and how to contact me.

  Mobile version of this page Mobile version of this page


 

XML header and childNodes

nodes, document element, childnodes, ajax, text/xml

25th of July 2007

I discovered something really odd today that maybe a seasoned AJAX guru already knew as a legendary bug which might even have a name. I was developing a little AJAX method on the server side that returned this:

 <?xml version="1.0"?>
 <sections>
   <section>
     <number>001</number>
     <title>PLug 1</title>
   </section>
   <section>
     <number>003</number>
     <title>PLug 3 xyz</title>
   </section>
 </sections>

 Note: The Content-Type used was "text/xml"

I used jQuery to kick off the AJAX call and then I loop over the document element returned with childNodes almost like this:

 children = data.childNodes[0].childNodes;
 for (var i=0, len=children.length; i<len; i++)
   // bla bla

It was working fine in Firefox and of course not in IE 6.0.

Long story short, the solution was to not attach the first line: <?xml version="1.0"?> because with that line, in IE the object data.childNodes[0].childNodes did not contain any further nodes to loop over. Why??? No idea. So now my server side sends this instead:

 <sections>
   <section>
     <number>001</number>
     <title>PLug 1</title>
   </section>
   <section>
     <number>003</number>
     <title>PLug 3 xyz</title>
   </section>
 </sections>

To make it work now I just removed that first line. I haven't had to worry about unicode problems yet but I would use this first line to describe the unicode encoding if non-ASCII. Now I can't, which makes me a bit worried that I might run into encoding problems one day.


Comment

 
Name:
Email:
hide my email address.

Your email address will be encoded to prevent email-extraction spiders from reading it so you won't get spammed if you decide to show your email address.