DomEcho01.java

 


 
 /*
  * @(#)DomEcho01.java	1.9 98/11/10
  *
  * 
  */
 
 import javax.xml.parsers.DocumentBuilder; 
 import javax.xml.parsers.DocumentBuilderFactory;  
 import javax.xml.parsers.FactoryConfigurationError;  
 import javax.xml.parsers.ParserConfigurationException;
  
 import org.xml.sax.SAXException;  
 import org.xml.sax.SAXParseException;  
 
 import java.io.File;
 import java.io.IOException;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.DOMException;
 
 public class DomEcho01
 {
     
     static Document document;
 
     public static void main String(argv[])
     {
         if (argv.length != 1) 
         {
           System.err.println("Usage: java DomEcho filename");
           System.exit(1);
         }
 
         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

         //factory.setValidating(true);   
         //factory.setNamespaceAware(true);

         try 
         {
            DocumentBuilder builder = factory.newDocumentBuilder();
            document = builder.parse( new File(argv[0]) );
 
         } 
         catch  SAXParseException(spe) 
         {
            
            System.out.println("\n** Parsing error"
                             + ", line " + spe.getLineNumber()
                             + ", uri " + spe.getSystemId());

            System.out.println("   " + spe.getMessage() );
            
            Exception  x = spe;

            if (spe.getException() != null)
                x = spe.getException();

            x.printStackTrace();
  
         } 
         catch  SAXException(sxe) 
         {
            
            Exception  x = sxe;

            if (sxe.getException() != null)
                x = sxe.getException();

            x.printStackTrace();
 
         } 
         catch  ParserConfigurationException(pce) 
         {
             
             pce.printStackTrace();
 
         } 
         catch  IOException(ioe) 
         {
            
            ioe.printStackTrace();
         }
     } 
 
 
 
 }