up
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.*;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
import java.io.IOException;
import java.io.File;
public class DOMxml {
public static void main(String args[])
throws ParserConfigurationException,
SAXException, IOException {
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder =
factory.newDocumentBuilder();
Document doc = builder.parse (new File(args[0]).toURL().toString());
new TreeTraverser (doc);
} }
class TreeTraverser{
TreeTraverser (Node node){
<.visit xml context node.>
int i;
if( node.hasAttributes() ){
NamedNodeMap attributes = node.getAttributes() ;
for( i=0; i < attributes.getLength(); i++ ){
new TreeTraverser ( attributes.item(i) );
} }
if( node.hasChildNodes() ){
NodeList children = node.getChildNodes();
for( i=0; i < children.getLength(); i++ ){
new TreeTraverser ( children.item(i) );
} } }
<.the visit methods.>
} -_-_-