Small, minimalistic and fast XML library for Java?

2019-05-07 16:42发布

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.

3条回答
来,给爷笑一个
2楼-- · 2019-05-07 16:49

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楼-- · 2019-05-07 17:10

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.

查看更多
再贱就再见
4楼-- · 2019-05-07 17:12

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

查看更多
登录 后发表回答