08-03-2009 07:06 AM
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.
08-03-2009 07:37 AM
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.
08-03-2009 08:45 AM
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.
08-03-2009 10:27 AM
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.