Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
jromanoski
Posts: 90
Registered: ‎09-07-2010
My Device: Not Specified

Parsing InputStream

Hello,

 

I'm trying to parse an InputStream that contains XML information with SAX.

 

 

private void parserInput(InputStream in)
 {
  
 try {
 SAXParserFactory saxfact = SAXParserFactory.newInstance();
 SAXParser sp = saxfact.newSAXParser();
 sp.parse(in, handler)
 } catch (ParserConfigurationException e) {
 e.printStackTrace();
 } catch (SAXException e) {
 e.printStackTrace();
 }
 }

 

private void parserInput(InputStream in) {  

 try {

 SAXParserFactory saxfact = SAXParserFactory.newInstance();

 SAXParser sp = saxfact.newSAXParser();

 sp.parse(in, handler)

 }

catch (ParserConfigurationException e) {

 e.printStackTrace();

 

 

But i don't know exactly what do i have to do with that handler and how do i get the XML tags from the inputstream. I was used to do this in a different way but it's not working with BB JRE...

 

Any help please?

New Developer
rodrifox
Posts: 35
Registered: ‎12-22-2009
My Device: Bold 9700

Re: Parsing InputStream

Hi,

 

You need to create a class that extends from DefaultHandler in order to properly parse each tag in your XML. Have you seen this thread? http://supportforums.blackberry.com/t5/Java-Development/sax-parsing/m-p/575975.

 

I'm not actually using SAX, since kXML library works great and faster. I've put a short tutorial on how to include it in your BlackBerry project here: http://www.wilkonit.com/site/component/lyftenbloggie/2010/09/01/2-parse-serialize-xml-blackberry.

 

 

Regards!

-------------
Rodrigo Bravo
http://www.wilkonit.com