2011-03-30 10:23:26Something to discuss about javascript.XML
Paul D

chillcast@googlemail...
82.18.130.183

Javascript/XML reading problem.

Got a weird thing happening if anyone wants to analyse it??

I'm reading Johns XML file

Which consists of entries ordered like this:

year
       bias
       bias
       bias
      date
/year


year
      bias
      bias
      bias
      date
/year

You can view the XML here:

http://www.skepticalscience.com/peerfeed.php?f=years

My code looks something like this (uses an XMLhttprequest):

var YearEntries = xmlDoc.getElementsByTagName("year");
   for (var j=0; j<YearEntries.length; j++)
   {        
          for (var n=0; n < YearEntries[j].getElementsByTagName("bias")[0].childNodes[0].length; n++)
          {

blah, blah

The problem is that sometimes YearEntries[j].getElementsByTagName("bias")[0].childNodes[0].length
returns 4 bias entries instead of 3.
So for now I have hard coded 3 entries in the loop, which works.
Its weird because it runs through all the year entries and returns the correct value (3), but goes wrong at the 2007 entry.

Currently I am carrying on with the loop hard coded for 3 entries.

If anyone has any ideas, I would be interested.

2011-03-30 11:31:42
Daniel Bailey
Daniel Bailey
yooper49855@hotmail...
97.83.150.37

You may want to get into touch with Oslo (new techhie active on the forum); has a bio in the meet-the-author's section.

Maybe he can help (I sure can't).

2011-03-30 22:38:13
Paul D

chillcast@googlemail...
82.18.130.183

John requested that we should exchange knowledge and discuss these things on the forum.

The problem isn't holding me up, but it isn't a good idea to hard code these things, since in the future it might be decided to increase the number of bias entries in the XML file.

My strategy for dealing with it is to at some point put a version of the XML reading code in a separate test file so I can see what it does in isolation from the rest. But at the moment I am keen to get the circles animated and displayed.

2011-03-31 01:50:12
oslo

borchinfolab@gmail...
90.149.33.182

I'll look into it.

2011-03-31 05:05:05
oslo

borchinfolab@gmail...
90.149.33.182

I used Ext Js to read the data into a table and it works perfectly, without errors.

I think Firefox reads text (empty space) and put it into nodes - so it would report more nodes than is actually present in the xml file.

http://www.w3schools.com/dom/dom_mozilla_vs_ie.asp

If you use Firefox this is probably the reason - have experienced this some time ago (this "glitch" might be present in other browsers as well)...

It is quite all right to hard code for 3 nodes - or you could read all nodes but check for node type.

2011-03-31 05:24:02
Paul D

chillcast@googlemail...
82.18.130.183

Ahh. thanks for that. I am using firefox.

But it also happened in Opera??! Although I didn't do any extensive testing in that.

That last option sounds good.

Cheers.

John, Its all your fault :-) (I jest)

2011-03-31 05:43:06
oslo

borchinfolab@gmail...
90.149.33.182

Sounds reasonable if you get the same result in Opera - I would be surprised if Opera use another code base on this than Firefox - there is an open xml project, and both browser probably use the same code for parsing xml - well, this is my guess.