469,568 Members | 1,568 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,568 developers. It's quick & easy.

Javascript var in recursive calls

My problem is related to this thread. I wrote an XML DOM parser. It parses the complete tree on IE, but it stops after the first downstream on FireFox, SeaMonkey and Opera. This is a simplified code that reproduces the issue:

Expand|Select|Wrap|Line Numbers
  1. function PrintNode(node)
  2. {
  3.     AddText("<b>"+node.nodeName+"</b>="+node.nodeValue+" ("+node.childNodes.length+" children)");
  4.     if (!node.hasChildNodes) return;
  5.     AddText("<ul>");
  6.     var child=node.firstChild;
  7.     do
  8.     {
  9.         if (ShowMsg && !confirm(Text)) return;
  10.         AddText("<li>");
  11.         PrintNode(child);
  12.         AddText("</li>");
  13.     }
  14.     while (child=child.nextSibling);
  15.     AddText("</ul>");
  16. }
So, why is this working in IE only? Maybe you can point me to some JScript/JavaScript difference. (A JavaScript/C++ comparison would also help.)

nb. I've already found a solution that works on all browsers:

Expand|Select|Wrap|Line Numbers
  1.     for (var child=node.firstChild;child;child=child.nextSibling)
Feb 28 '07 #1
1 1491
16,027 Expert Mod 8TB
Welcome to The Scripts.

Try using the childNodes array as shown in this page (see the source code).
Mar 1 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by | last post: by
7 posts views Thread by aurora | last post: by
6 posts views Thread by bonehead | last post: by
13 posts views Thread by jm.suresh | last post: by
41 posts views Thread by Harry | last post: by
3 posts views Thread by from.future.import | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.