[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Guys!!! Help me out in this!!!

Subject: Guys!!! Help me out in this!!!
From: Bansi Giri <bansi97@xxxxxxxxx>
Date: Tue, 14 Nov 2000 19:48:18 -0800 (PST)
bansi help
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.