tags:

views:

110

answers:

6

Hi Pro's, which parser (java) would you recommend for parsing GPX data? Im looking for a one that is very intuitive to use and should not need too much RAM (it seems that DOM requires too much, doesn't it?). I have no idea about parsing xml, so it is time for me to learn this ;-)

My documents are not very huge and are always read twice(a point for DOM), but I want to keep as few things as possible in RAM.

What would you do in this situation? Which one would you coose and why?

A: 

I would suggest XPP,

http://www.extreme.indiana.edu/xgws/xsoap/xpp/

It's more efficient DOM and easier to use than SAX.

STAX is another popuplar pull parser,

http://stax.codehaus.org/Home

ZZ Coder
A: 

Depending on what your wanting to do with the xml, JAXB might be a possibility. The idea is to convert xml into POJOs without messing (directly) with the parsers. (Although one still can mess with the parsers if needed.) Plus I've found that since JAXB is in the javax root package it tends to play nicer with standards.

Quotidian
if the program is used as it should be used, the XML file will be edited once at maximum (if invalid data at receiving) occures. during the use of the programm it is read 2 or 3 times...
poeschlorn
If there's a chance of invalid data, I'd definitely use JAXB. There's a fairly robust validation / adapter framework which is implemented at the marshal/unmarshal steps.
Quotidian
+2  A: 

Unless you have a special reason to use a third-party library for XML parsing, I'd just use the standard Java API. See the package javax.xml.parsers. Assuming you have the XML in a file, you can parse it into an org.w3c.dom.Document (also part of Java's standard API) like this:

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new File(filename));

Since your files are not so large, using DOM would be the easiest and most obvious choice.

You can use the methods of the Document object and related objects (see the classes in the org.w3c.dom package) to get at the data, or use XPath (see the package javax.xml.xpath).

JAXB, that Quotidian mentions, is also in the standard API since Java 6, but it might be a bit more work to set up than using the standard DOM API.

Jesper
thank you, I'm gonna try this :)
poeschlorn
A: 

XOM is very easy to use, if you are thinking of using something like DOM, JDOM, or DOM4J I think you should check out XOM. It was created by a JDOM developer who was trying to make the api more user-friendly. Since it was built to be approachable and has good online documentation I would recommend it as a good starting point for a beginner.

Nathan Hughes
A: 

I'm a big fan of apache digester since it lets you define translation rules and go straight to Java objects. I think that JaxB does something similar.

Uri
A: 

I would start with an IDE like Oxygen.

dacracot