home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1999 October / pcp156b.iso / alphawrk / TEXML / TEXML.ZIP / com / ibm / texml / ProcXML.java < prev    next >
Encoding:
Java Source  |  1999-05-13  |  1.4 KB  |  56 lines

  1. package com.ibm.texml;
  2.  
  3. import java.io.*;
  4. import com.ibm.xml.parsers.*;
  5. import org.w3c.dom.*;
  6. import org.xml.sax.*;
  7.  
  8. /**
  9. Provides static methods for reading and parsing an XML file and producing a
  10. document (DOM) structure.
  11. */
  12. public class ProcXML
  13.   {
  14.   /**
  15.   Invoke the XML parser on the file.
  16.   @param inputXML file handle of XML source.
  17.   @return the Document node of the DOM.
  18.   */
  19.   public static Document parseXML(File inputXML)
  20.   throws FileNotFoundException, IOException, SAXException
  21.     {
  22.     NonValidatingDOMParser parser = new NonValidatingDOMParser();
  23.     parser.setExpandEntityReferences(true);
  24.     parser.parse(inputXML.getName());
  25.     return parser.getDocument();
  26.     }
  27.  
  28.   /**
  29.   Read XML input file.
  30.   @param inputXML name of XML input file
  31.   */
  32.   public static Document parseXML(String inputXML)
  33.     {
  34.     Document doc = null;
  35.     File finputXML = new File(inputXML);
  36.     try
  37.       {
  38.       doc = parseXML(finputXML);
  39.       }
  40.     catch (FileNotFoundException e)
  41.       {
  42.       System.out.println("Missing XML file, "+inputXML);
  43.       }
  44.     catch (IOException e)
  45.       {
  46.       System.out.println("Error reading XML file, "+inputXML);
  47.       System.out.println("IO error message is, "+e.getMessage());
  48.       }
  49.     catch (SAXException e)
  50.       {
  51.       System.out.println("Failed to parse input. "+e.getMessage());
  52.       }
  53.     return doc;
  54.     }
  55.   }
  56.