SAX1 vs SAX2
"Luzum, Steven J" <[email protected]>
| Newsgroups | gmane.text.xml.sax.general |
|---|---|
| Message-ID | <45891E243FF2E5498C85C8A5340E94FA907EF8@exccpgo04.corp.xcelenergy.com> |
> I have a couple of questions I hope you can help me out with. I took over the maintenance of an app that uses XML to display reports and query results. I am trying to resolve the Deprecated APIs when I compile. > > There is a XMLParser object that uses a couple of SAX1 methods that I am trying to replace. (see attached) > > I have everything replaced except the following code: > > //org.xml.sax.Parser parser = new com.sun.xml.parser.Parser(); //Deprecated <=== Original code > org.xml.sax.XMLReader parser = new com.sun.xml.XMLReader.parse(); <=== What I'm trying to replace it with > > here is the compiling error I get: > com/xcel/servconn/dcf/sax/XMLParser.java [96:1] cannot resolve symbol > symbol : class parse > location: package XMLReader > org.xml.sax.XMLReader parser = new com.sun.xml.XMLReader.parse(); > ^ > 1 error > Errors compiling XMLParser. > > When I deploy, I deploy with XML.jar as an additional package. Do I need to get a new XMl.jar file in order for this to compile properly? Where would I get it? > > .> > <<XMLParserNew2.txt>> > Thanks in advance for any assistance > > Steve >
XMLParserNew2.txt
(text/plain, 4.4 KB)
/*
* XMLParser.java
*
* Created on June 22, 2001, 5:59 PM
* Revised on May 17, 2002, 8:45 AM
*/
/**
* This class is responsible for invoking the Sax parser and parses the provided file.
* <BR>
*/
package com.xcel.servconn.dcf.sax;
import java.io.*;
import java.net.*;
import java.util.*;
import org.xml.sax.*;
import org.xml.sax.ext.*;
//import org.xml.sax.helpers.ParserFactory; //Deprecated Class
import org.xml.sax.helpers.XMLReaderFactory; //New Class
import org.xml.sax.helpers.DefaultHandler; //New Class
import org.xml.sax.XMLReader; //New Class
import org.xml.sax.ContentHandler; //New Class
//import org.xml.sax.DocumentHandler; //Deprecated Class
import com.xcel.servconn.dcf.*;
/**
*
* @author ServConn Team (Mark D. Johnson, Steven J. Luzum, Muhammad U. Khan)
* @version 3.0 released to production 9/22/01 to the South only
* @version 3.1 released to production 2/11/02 to the South and Wisconsin
* @version 3.2 released to production 4/22/02 to all of Xcel.
* @version 3.3 released to Production 10/15/02 to all of Xcel.
* @version 4.0 released to production 3/3/02 to all of Xcel.
*/
public class XMLParser {
/**
* It initiate the Sax parser when it is passed the Sax base handle and an input source
* @param xmlHandler Sax Handle Base
* @param inputsource Input source
* @exception BusinessLogicException
*/
//public static void parseXML(HandlerBase xmlHandler, InputSource inputSource) throws BusinessLogicException { //Deprecated Method
public static void parseXML(DefaultHandler xmlHandler, InputSource inputSource) throws BusinessLogicException {
try {
parse(xmlHandler, inputSource);
} catch (Exception ex){
new BusinessLogicException(ex.getMessage());
//System.out.println(e);
//e.printStackTrace();
}
}
/**
* It initiate the Sax parser when it is passed the Sax base handle and a String
* It creates an input source for the provided string.
* @param xmlHandler Sax Handle Base
* @param xmlString
* @exception BusinessLogicException
*/
//public static void parseXML(HandlerBase xmlHandler, String xmlString) throws BusinessLogicException { //Deprecated Method
public static void parseXML(DefaultHandler xmlHandler, String xmlString) throws BusinessLogicException {
try {
StringReader xmlReader = new StringReader(xmlString);
InputSource inputSource = new InputSource(xmlReader);
parse(xmlHandler, inputSource);
} catch (Exception ex){
new BusinessLogicException(ex.getMessage());
//System.out.println(e);
//e.printStackTrace();
}
}
/**
* Create a Sax parser using Sax interfaces and classes. Also create
* document handler for the XML document.
* @param xmlHandler Sax Handle Base
* @param is Input Source
* @exception Default Exception
* @exception SAXParseException
*/
//private static void parse(HandlerBase handler, InputSource is) throws BusinessLogicException { //Deprecated Method
private static void parse(DefaultHandler handler, InputSource is) throws BusinessLogicException {
try {
//create a SAX parser using SAX interfaces and classes
//org.xml.sax.Parser parser = new com.sun.xml.parser.Parser(); //Deprecated
org.xml.sax.XMLReader parser = new com.sun.xml.XMLReader.parse(); <===== Compile error!!!!!!!!
//create document handler to do something useful with the XML
//document being parsed by the parser.
//parser.setDocumentHandler(handler); //Deprecated Method
parser.setContentHandler(handler);
parser.setErrorHandler(new XmlErrorHandler());
parser.parse(is);
} catch (SAXParseException saxe){
System.out.println("An error occured in XmlErrorHanlder. Line number: " + saxe.getLineNumber());
System.out.println("The error message is: " + saxe.getMessage());
saxe.printStackTrace();
} catch (Exception ex){
System.out.println("Exception parsing: " + ex.getMessage());
ex.printStackTrace();
}
}
}