XML header and childNodes

26 July 2007   0 comments   Web development

Mind That Age!

This blog post is 11 years old! Most likely, its content is outdated. Especially if it's technical.

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.

Comments

Thank you for posting a comment

Your email will never ever be published


Related posts

Previous:
How did Google do that? 14 July 2007
Next:
Interesting lesson learnt on shortcut taking in usability 02 August 2007
Related by Keyword:
Using Lovefield as an AJAX proxy maybe 30 September 2015
AJAX or not 22 December 2014
Lazy loading below the fold 26 October 2013
IssueTrackerProduct featured on Ajaxian.com 26 January 2006
IssueTrackerProduct 0.7 released 16 December 2005
Related by Text:
HTML Tree on Hacker News 18 May 2014
YouTube - Nigella's XXXmas 19 December 2008
How and why to use django-mongokit (aka. Django to MongoDB) 08 March 2010
How to track Google Analytics pageviews on non-web requests (with Python) 03 May 2016
hashin 0.7.0 and multiple packages 30 August 2016