How do you print the contents of an XML document using the DOM, i.e. using the org.w3c.dom.* interfaces?

Pramod Hirole

The org.w3c.dom.* package provides a Node interface which defines methods such as "getNodeName()" ,"getNodeType()", "getNodeValue()" for getting the information about the current node. There are also other methods such as "getPreviousSibling()", "getNextSibling()", "getChild()" for traversing the XML document.

Given a reference to Document you can traverse through the document using the above methods, printing each node as it is visited.