Small, minimalistic and fast XML library for Java?

2019-05-07 16:53发布

问题:

Sometimes I need to parse XML file - and only parse, and I don't want to do this manually via String.indexOf. So my need would be to use possibly smallest and fast XML parsing library. Unfortunatelly, I don't know anything similar to GSON (180kb).

I've imported dom4j, but after that I've got exception:

java.lang.NoClassDefFoundError: org/jaxen/JaxenException

So I've added jaxen dependency (maven), and this is very shocking experience: about 7MB dependencies added, the biggest from them xercesImpl and icu4j.

Another guess is Jericho, but this is mostly designed for parsing bad-formed HTML, and it's over 2MB - surely there could be something smaller available.

So, could you please recommend me some good library? The minimal code size is the most important thing here. At best it should about the size of GSON.

回答1:

Have a look at NanoXML - download site

It is a very small DOM-based parser library, I've used it in the past and it worked well. It is not necessarily efficient but it is tiny.



回答2:

JAXB. It is part of the standard Java platform so you don't need any extra libraries. It will bind XML directly to Java classes.



回答3:

What's wrong with the javax.xml.parsers in the Java Standard Libary?

http://docs.oracle.com/javase/7/docs/api/javax/xml/parsers/DocumentBuilder.html