Visiting All the Nodes in a DOM Document

// Obtain an DOM document; this method is implemented in // The Quintessential Program to Create a DOM Document from an XML File Document doc = parseXmlFile("infilename.xml", true); visit(doc, 0); // This method visits all the nodes in a DOM tree public static void visit(Node node, int level) { // Process node // If there are any children, visit each one NodeList list = node.getChildNodes(); for (int i=0; i<list.getLength(); i++) { // Get child node Node childNode = list.item(i); // Visit child node visit(childNode, level+1); } }

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.