Putting all together


 import org.w3c.dom.*;
 import org.apache.xerces.parsers.DOMParser;

 class DisplayElements
 {
    public static void displayDocument(String uri)
    {
       try{
	  DOMParser parser = new DOMParser();
	  parser.parse(uri);
	  Document doc = parser.getDocument();
	  display_names(doc);
       } 
       catch (Exception e) {
          e.printStackTrace(System.err);
       }
    }

    public static void display_names(Node node)
    {
       if(node == null) {
	  return;
       }
       int type = node.getNodeType();
       switch (type) {
          case Node.DOCUMENT_NODE: {
	     display_names(((Document)node).getDocumentElement());
	     break;
	  }
	  case Node.ELEMENT_NODE: {
	     System.out.println("Element : " + node.getNodeName());
		
	     NodeList childNodes = node.getChildNodes();	
	     if(childNodes != null) {
	        int length = childNodes.getLength();
	        for (int loopIndex = 0; loopIndex < length ; loopIndex++)
	        {
	           display_names(childNodes.item(loopIndex));
	        }
	     }
	     break;
	  }   
       }
    }
 }

 public class DOMNameElements
 {
    public static void main(String[] args)
    {
       DisplayElements.displayDocument(args[0]);
    }
 }