home *** CD-ROM | disk | FTP | other *** search
Java Source | 1999-05-13 | 1.4 KB | 56 lines |
- package com.ibm.texml;
-
- import java.io.*;
- import com.ibm.xml.parsers.*;
- import org.w3c.dom.*;
- import org.xml.sax.*;
-
- /**
- Provides static methods for reading and parsing an XML file and producing a
- document (DOM) structure.
- */
- public class ProcXML
- {
- /**
- Invoke the XML parser on the file.
- @param inputXML file handle of XML source.
- @return the Document node of the DOM.
- */
- public static Document parseXML(File inputXML)
- throws FileNotFoundException, IOException, SAXException
- {
- NonValidatingDOMParser parser = new NonValidatingDOMParser();
- parser.setExpandEntityReferences(true);
- parser.parse(inputXML.getName());
- return parser.getDocument();
- }
-
- /**
- Read XML input file.
- @param inputXML name of XML input file
- */
- public static Document parseXML(String inputXML)
- {
- Document doc = null;
- File finputXML = new File(inputXML);
- try
- {
- doc = parseXML(finputXML);
- }
- catch (FileNotFoundException e)
- {
- System.out.println("Missing XML file, "+inputXML);
- }
- catch (IOException e)
- {
- System.out.println("Error reading XML file, "+inputXML);
- System.out.println("IO error message is, "+e.getMessage());
- }
- catch (SAXException e)
- {
- System.out.println("Failed to parse input. "+e.getMessage());
- }
- return doc;
- }
- }
-