Zoo tutorials: [ SQL | Java | Linux | XML ]

A Gentle Introduction to xml

Recursing over DOM

Question 1: Walkover

For trees of unknown depth we must sometimes use recursive routines to extract data. We have such a file in yahoo.xml which, as you might imagine, could be pretty deep.

The function walkover takes a node n as input. The other parameter x gives the depth of the node. We visit each node, then visit each if the children in turn. This is a "pre-order" walk. We visit the parent before we visit the children.

Java DOM

Question 2: Walkover with an accumulating parameter

This time the s parameter builds up the path of the node so far.

Java DOM