How to get a data ?

olivier corre <[email protected]> Wed, 15 Oct 2003 10:05:33 +0200
Newsgroups gmane.text.xml.sax.general
Organization 6WIND
Message-ID <[email protected]>
Hi all,

Sorry for the low level of my question : I'm a newbee :)

So, I typically have an XML file containing :

<title>
The best XML book
</title>

I would like, please, to know how to get the value of the title (that is 
"The best XML book") using sax
I don't manage to succeed it by now.
My code is as follows :



public class testSAX extends DefaultHandler {

    StringBuffer content = new StringBuffer();

    public testSAX() {
       super();
    }

    public void parse() {
       try {
	SAXParser parser = new SAXParser();
	parser.setContentHandler(this);
	parser.parse("xmlFile.xml");
       } catch (SAXException e) {
            System.err.println (e);
       } catch (IOException e) {
	   System.err.println (e);
       }
    }

    public void startDocument ()
    {
       System.out.println("Start document");
    }

    public void endDocument ()
    {
       System.out.println("End document");
    }

    public void startElement (String uri, String local,
	String qName, Attributes atts)  {
       if (local.equals("title")) {
          content.setLength(0);
       }
    }

    public void endElement(String uri, String local,
	String qName, Attributes atts) throws SAXException {
       String eventName = new String();
       content.toString();
       System.out.println("EVT = " + eventName);
    }

    public void characters (char ch[], int start, int length) {
       content.append(new String(ch, start, length));
    }

}



Many many many thanks to anybody who can help me :)
Best Regards

Olivier



-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
SourceForge.net hosts over 70,000 Open Source Projects.
See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
_______________________________________________
List: [email protected]
See:  http://www.saxproject.org
https://lists.sourceforge.net/lists/listinfo/sax-users