Hi Vijay,
ParserAdapter class wraps a SAX1 org.xml.sax.Parser Parser and makes it act as a SAX2
org.xml.sax.XMLReader XMLReader,with feature, property, and Namespace support. If you
want to
use own sax parser , then parser must implements either org.xml.sax.Parser or
org.xml.sax.XmlReader Interface.
Comment
//XMLReader xr = new ParserAdapter();
line in your program and add this
XMLReader xr =XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
Cheers,
Arun Yadav
Vijay wrote:
> I have a query regarding SAX parser. my java class uses SAX
> 2.0.
> It needs a driver. I downloaded xerces 1.4.3 to get the class
> which implements XMLReader interface. This class
> (org.xml.sax.helpers.ParserAdapter) acts as a parser driver.
> correct me if I am wrong. After compiling i give
> (java -D org.xml.sax.helpers.ParserAdapter MySAXApp roses.xml)
> on the command line. The thing is in classpath I have given
> both xerces 2.0.0 and xerces 1.4.3. I have to use 1.4.3 's
> adapter classes. How will i use them. is there any other way
> to have driver for sax2.0 I am pasting my java class below.
> Thanks
> Vijay
>
> import java.io.FileReader;
>
> import org.xml.sax.XMLReader;
> import org.xml.sax.Attributes;
> import org.xml.sax.InputSource;
> import org.xml.sax.helpers.XMLReaderFactory;
> import org.xml.sax.helpers.DefaultHandler;
> import org.xml.sax.helpers.ParserAdapter;
>
> public class MySAXApp extends DefaultHandler
> {
>
> public static void main (String args[])
> throws Exception
> {
>
> XMLReader xr = new ParserAdapter();
> MySAXApp handler = new MySAXApp();
> xr.setContentHandler(handler);
> xr.setErrorHandler(handler);
>
> // Parse each file provided
> on the
> // command line.
> for (int i = 0; i < args.length; i++) {
> FileReader r = new FileReader(args[i]);
> xr.parse(new InputSource(r));
> }
> }
>
>
> public MySAXApp ()
> {
> super();
> }
>
>
> //////////////////////////////////////////////////////////
> //////////
> // Event handlers.
> //////////////////////////////////////////////////////////
> //////////
>
>
> public void startDocument ()
> {
> System.out.println("Start document");
> }
>
>
> public void endDocument ()
> {
> System.out.println("End document");
> }
>
>
> public void startElement (String uri, String name,
> String qName, Attributes atts)
> {
> System.out.println("Start element: {" + uri + "}" +
> name);
> }
>
>
> public void endElement (String uri, String name, String
> qName)
> {
> System.out.println("End element: {" + uri + "}" +
> name);
> }
>
>
> public void characters (char ch[], int start, int length)
> {
> System.out.print("Characters: \"");
> for (int i = start; i < start + length; i++) {
> switch (ch[i]) {
> case '\\':
> System.out.print("\\\\");
> break;
> case '"':
> System.out.print("\\\"");
> break;
> case '\n':
> System.out.print("\\n");
> break;
> case '\r':
> System.out.print("\\r");
> break;
> case '\t':
> System.out.print("\\t");
> break;
> default:
> System.out.print(ch[i]);
> break;
> }
> }
> System.out.print("\"\n");
> }
>
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]