Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can someone check a page of code for me?

Status
Not open for further replies.

zolah

Technical User
May 21, 2001
13
US
I have a page of code straight from a book that is not working. Can someone look at it and explain to me why I get the error message "childNodes" is "null" or not an object? I am getting very frustrated.
Thanks in advance
Chris
 
Hello,
The code seems to be taken from a book and it should be working.
You did (or someone who typed) a typo:
var RootElement1=message.documentELement;

instead of correct

var RootElement1=message.documentElement;

Sorry, but documentElement is a property and it should be written in this way, small and capital letters matter.

There is another mistyping:
in row:

case "P":
bodydata.innerText=CurrentNode.text;


should be:


case "P":
pdata.innerText=CurrentNode.text;

as pdata is the name of div tag.

Hope this helps.
D.
 
we will check it out right away. Thank you so much for taking the time to look at it. We were getting nowhere real fast.
 
Thank you so much dianal! Sure enough it worked!! We looked at that code all day and never saw it.
 
Hello,
May be I should post how I found the error?
:)

1) I commented the line that gives error.
// var nodecount=RootElement1.childNodes.length;
This is very handy technique to find which caused the error.
Usually is something before the line that gives the error.

2) Since I know that there are 4 elements in xml nodes, I hardcoded:
var nodecount = 4;
This is because I do not want to recieve another error that nodecount has no value.
You can guess some value and hard code it.

3) Then checked what the browser display - WOW - it shows an alert that Root Element is null and The data of the XML file cannot be accessed
So, so, there could be something wrong with the Root Element.
4) Let see what is in there?

var RootElement1=message.documentELement;

RootElement1 cannot be a prob
message is the id of xml island, everithing is ok there, no small/caps diffrences

5) Let's check MSDN for property documentELement

See whole reference when you have time.
I have CD version of MSDN and it is much quicker. :)

Let's copy their example line
var RootElement1=message.documentElement;

6) Check again:
It worked till SUBJECT, then got an error.

Time to rollback unnecessary changes, still error, check the bodydata - it appeared only 1 time - so it should be pdata.

Voala, checked, corrected and free from bugs!

Wish you success!
D.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top