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
Posts: 105
Registered: ‎07-19-2009
My Device: Not Specified

XML parsing

I am developing BB native application. I am trying to retrieve the response of the url from server. The url returns response in XML format. I need to parse the url and need to render the parsed response in the screen.

 

What are the steps to be done to parse the XML and how to do it?

 

 Thanks for any help.

 

 

Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: XML parsing

Have a look at the xmldemo  example shipped with the JDE.

 

Regards

Bikas

Developer
Posts: 105
Registered: ‎07-19-2009
My Device: Not Specified

Re: XML parsing

XMLDEMO seems to be parsing the content from the xml file. But, in my case url response in xml format and that has to be parsed.
Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: XML parsing

Maybe I am fully getting you. But I think in both cases you have to load xml string in a inputstream.

 

Like in your case som something like:

 

InputScream inputStream = httpConnection.openInputStream();

And in the example xml String is loading from file:

 

InputStream inputStream = getClass().getResourceAsStream( _xmlFileName );

 And the rest is to parse the XML.

 

Regards

Bikas

 

 

 

 

 

Developer
Posts: 105
Registered: ‎07-19-2009
My Device: Not Specified

Re: XML parsing

Yes. you are right. But, there is one class in BB API named DefaultHandler which is also for xml parsing.

 

What's the use of this class? Can we do xml parsing using this class?

 

 

Just want to know more information in this class.

 

 

Developer
Posts: 242
Registered: ‎01-29-2009
My Device: Not Specified

Re: XML parsing

As your probably know there are two types of XML parsers: A DOM parser and a SAX parser. The first one reads the entire XML in and creates an in-memory document representation of the XML file which you can then access with methods like getElementById(..) etc. The second type of parser is a SAX parser which parses the XML as it reads the file. It's an event driven parser, ie whenever it comes across an XML element it will notify the handler. This parser is less memory hungry since you are not reading the whole XML into memory first. And here, the DefaultHandler is being used. So you need to subclass it and overwrite the methods you need.

 

Hope this helps.

 

Daniel