[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Guys!!! Help me out in this!!!
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|