开发者

recommended parser for XML in java(absolute beginner to xml)

which parser (java) would you recommend for parsing GPX data? Im looking for a one that is very intuitive to use and should not ne开发者_StackOverflow中文版ed 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?


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.


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


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.


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.


I would start with an IDE like Oxygen.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜