Jump to content

Recommended Posts

I just made a new XML file for testing purposes and if I type...

<?xml etc?><root><main><firstchild></firstchild><secondchild></secondchild></main></root>

...it works perfectly fine.What I'm using to check is a body onLoad function():

startupload(){	 document.getElementById('body').innerHTML = xmlFile.getElementsByTagsName('main')[0].childNodes[0].nodeName + "<br />";	 document.getElementById('body').innerHTML += xmlFile.getElementsByTagsName('main')[0].childNodes[1].nodeName + "<br />";}

And this displays firstchild / secondchild nicely. But the problem's when I jump a few lines to type something (even though I hadn't, I just ENTER'ed a few lines) and it messes it all up.

<?xml etc?><root><main><firstchild></firstchild><secondchild></secondchild></main></root>

Simply by doing this Firefox's output becomes: "#text / firstchild" while IE's remain unchanged. Does anyone know what could be the cause of this?I'm using Notepad++ and I've also tried with the basic windows notepad, same results, encoding types UTF-8 and ISO-8859-1.

Link to post
Share on other sites

This is a perfectly well known issue... with IE. The whitespace between elements is also considered a node - a whitespace text node to be exact. Firefox reads it, and IE ignores it.You already know the way to work around the bug - don't use whitespace text nodes, as in your initial example. Alternatively, avoid using childNodes in favor of getElementsByTagName() and the like.

Link to post
Share on other sites

This seems to be another occasion in which IE is the more flexible, robust browser. I often wonder why it's so hated. Every piece of bad code I write and test works in IE. While FF et al make me learn and write better code, which is my goal, for those who don't care so much or who haven't the time/patience to learn, stubborn browsers just make life harder.

Link to post
Share on other sites
This seems to be another occasion in which IE is the more flexible, robust browser. I often wonder why it's so hated. Every piece of bad code I write and test works in IE. While FF et al make me learn and write better code, which is my goal, for those who don't care so much or who haven't the time/patience to learn, stubborn browsers just make life harder.
Firefox's consistent with almost everything you try, you also know it'll probably work on any browser just like that except IE.IE's supposedly good, it makes the designer think of ways to work around it's bugs with creativity - alot of creativity.
This is a perfectly well known issue... with IE. The whitespace between elements is also considered a node - a whitespace text node to be exact. Firefox reads it, and IE ignores it.
Unfortunately I can't do that, since I intended to use that to read how many childs that element had (and get it's names and some atts) and display on mouse over/out.Instead I loaded a hidden div with PHP and set it to show onmouse over events... not exactly what I wanted but it's working.
Link to post
Share on other sites
Unfortunately I can't do that, since I intended to use that to read how many childs that element had (and get it's names and some atts) and display on mouse over/out.
Short of modifying your XML, you can modify your script. Rather than just getting all the child nodes and returning a count (or whatever it is you're trying to do), you can get all the child nodes and then iterate through them, look at the nodeType, and only count the Element nodes.
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...