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;
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.