Subject: Guys!!! Help me out in this!!! From: Bansi Giri <bansi97@xxxxxxxxx> Date: Tue, 14 Nov 2000 19:48:18 -0800 (PST) |
Hi: I tried to run this program (Source: JavaWorld, Programming XML in Java, Author: Mark Johnson, TitleFinder.java) using the latest IBM XML4J (implementation of SAX 2.0), by making the necessary changes since the example one was based on SAX1.0. While i am able to run the pgm using SAX 1.0, i am not able to get any output if i use SAX 2.0. Please help me out. Here are the programs: ******************************************************* //TitleFinder.java import java.io.IOException; import org.xml.sax.SAXException; import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.InputSource; import org.xml.sax.helpers.DefaultHandler; import org.apache.xerces.parsers.SAXParser; public class TitleFinder extends DefaultHandler { private boolean _isTitle = false; public TitleFinder() { super(); } public void startElement(String element,Attributes atts) { if (element.equals("TITLE")) { _isTitle = true; } } public void endElement(String element,Attributes atts) { if (element.equals("TITLE")) { _isTitle = false; } } public void characters(char[] ch, int start, int length) { if (_isTitle) { String sTitle = new String(ch,start,length); System.out.println("Title: "+ sTitle); } } public static void main(String[] args) { if (args.length !=1) { System.out.println("Usage: java TitleFinder [xmlfilename]"); System.exit(1); } // Creating the parser TitleFinder titleFinder = new TitleFinder(); try { SAXParser parser = new SAXParser(); parser.setContentHandler(titleFinder); parser.parse(new InputSource(args[0])); } catch (SAXException se) { se.printStackTrace(); } catch (IOException ie) { ie.printStackTrace(); } } // Main method } // Title Finder Class **************************************************** //poem.xml <?xml version="1.0"?> <poem> <AUTHOR>Ogden Nash</AUTHOR> <TITLE>Fleas</TITLE> <LINE>Adam</LINE> <LINE>Had 'em.</LINE> </poem> **************************************************** Thanks in advance Bye Bansi __________________________________________________ Do You Yahoo!? Yahoo! Calendar - Get organized for the holidays! http://calendar.yahoo.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
extracting SVGs from XML, Rosa I-Ting Cheng | Thread | RE: Guys!!! Help me out in this!!!, Kay Michael |
Re: XPATH and XSL(T), Ron Pronk | Date | how to replace line-feeds with spac, Chad Small |
Month |