XML library with a low footprint
Because of increasing configuration complexity, I want to introduce XML for my library's configuration files, and replace the existing properties files.
I would like to
- Publicly describe the XML structure with XSD (so the structure is documented and can be versioned)
- If possible, generate Java source code from that XSD for unmarshalling (like with JAXB / XJC). An alternative simple access method is OK too (e.g. simple XPath expressions)
- Have a low footprint and few or even none additional dependencies
If the footprint wasn't an issue, I'd choose JAXB right away. Are there similar libraries with a lower footprint?
EDIT: By footprint, I don't mean consumed memory bu开发者_开发百科t the "size" of the library in KB/number of classes. I'd expect my rather simple use-case to be coverable by a library with about 5-6 classes. I don't need the full power of JAXB.
JAXB is Low Footprint
A JAXB (JSR-222) implementation is also included as part of Java SE 6. The classes produced are just POJOs with the necessary annotations. In the question below the poster observes that the XMLBeans classes are four times bigger than the JAXB classes.
- Compiling huge schema into Java
Reducing the Number of Classes
If you start with Java classes (instead of generating them from an XML schema) you can normally keep the model smaller. The use of @XmlWrapperElement can help eliminate classes.
Reducing the Number of Classes Further
You can leverage the @XmlPath annotation in EclipseLink JAXB (MOXy), note I'm the tech lead. It leverages XPath to extend the JAXB mappings:
- http://bdoughan.blogspot.com/2010/09/xpath-based-mapping-geocode-example.html
For a zero-dependency solution use the DOM or the SAX parser that is part of every Java VM.
If you want Java type binding, stick with JAXB. Even if you find a smaller size library, you will loose out by using a non-standard solution that hasn't been as extensively tested or has as many developers who know how to use it.
If you are willing to consider using non XML-technologies, then you might want to look at my Config4J library (www.config4star.org). Comparing it to your wish list...
It provides an easy-to-use schema language.
The jar file is small (102KB) and it has no external dependencies.
The one capability missing from your wish list is a tool to automatically generate Java classes from a schema definition. However, the API of Config4J is simple enough that I'm not sure you would need such a code generator. Part III (The Config4JMS Case Study) of the Practical Usage Guide manual describes a technique for building a Spring-like library to create Java objects from configuration information.
精彩评论