views:

65

answers:

2

I'm looking to port my working Android XML parser to Blackberry, but the latter's Java feature set isn't as rich? I didn't want to have to write two parsers.

The following code yields "The method getXMLReader() is undefined for the type SAXParser":

SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser        sp  = spf.newSAXParser();
XMLReader        xr  = sp.getXMLReader();

Am I just out of luck here?

It's true I am trying to use org.xml.sax. I've read all the XML parsing discussions I can find out there. I wonder now if I can do this? Should I be using org.kxml2 instead because org.xml.sax makes no sense in BlackBerry land?

Thanks for any advice!

Russ

A: 

I'll answer this though I suspect there are others who know better.

My assessment of BlackBerry is that it's very poor in its API set. So, the SAX XML parser isn't available as it is on Android. Okay, that's cool. It's older and from a "smaller" time.

Worse though, it appears very challenging even to add a third-party library to a BlackBerry application. I followed various posts out there and failed to incorporate my own "third-party" JAR convincingly into a BlackBerry project despite the collective wisdom of a number of web pages on the topic.

I was thinking then of writing my own parsing engine to replace SAXParser.parse(). How hard could it be since my expectations for it are childishly simple?

Very hard indeed since it appears that the JavaME support for java.lang.Class is impoverished as well; it doesn't support the important reflection methods such as getDeclaredMethods() for use in creating the engine (into which I naturally wanted to plug my existing XML parser-handler).

Alas, this makes me wonder just what BlackBerry apps out there are able to do? I'm probably giving this world short shrift, but a couple of days were sufficient for me to go from zero to parsing XML texts off the web on Android, so I expected a very easy time of it here too.

Please feel free to shred my answer. If you can and do, especially if you add a real one, it will doubtless greatly benefit other folk new to BlackBerry development including me later when I come back to the problem (so that I can avoid brute-force stringing through the XML stream instead of cleanly parsing it).

Russ Bateman
A: 

You don't need to use the getXmlReader() method.

Now that you have your SAXParser use it to parse a document or stream.

SaxParserFactory spf = SaxParerFacter.newInstance();
SAXParser parser = spf.newSAXParser();

Open your stream or file and call and assign it to a variable. Let's call ours input.

parser.parse(input, handler)

The handler file will implement all of the call backs to handle the events the parser encounters.

I found this explanation of SAX to be quite helpful.

redwoolf