Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Please help me understand this DOM thing >Thread Next - Re: Please help me understand this DOM thing Re: Please help me understand this DOM thingTo: NULL Date: 3/4/2008 3:57:00 PM
RC wrote:
> BTW, why DOM has firstChild, lastChild but doesn't have nextChild?
It has nextSibling and previousSibling so you could access the first
child with var child = node.firstChild, then the next child with
child.nextSibling. And you can loop through the childNodes collection.
> function recursiveRead(node) {
> //alert(id);
> if (! node.hasChildNodes()) {
> alert(
> "Node name = " + node.nodeName + "\n" +
> "Node value = " + node.nodeValue + "\n" +
> "Node type = " + node.nodeType + "\n" +
> "Node id = " + node.id + "\n" +
> "Node data = " + node.data + "\n"
> );
> } else {
> nodeList = node.childNodes;
> alert(nodeList.length);
> for (var i = 0; i < nodeList.length; i++) {
> aNode = nodeList[i];
> recursiveRead(aNode);
It is generally a good idea to declare variables and use local
variables, it becomes mandatory once you want to write recursive
functions so use
else {
var nodeList = node.childNodes;
alert(nodeList.length);
for (var i = 0; i < nodeList.length; i++) {
var aNode = nodeList[i];
recursiveRead(aNode);
}
and your function should do what you want.
--
Martin Honnen
http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
