Hybrid SAX-DOM XML parser for Java
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Hybrid SAX-DOM XML parser for Java.

With Solna you can:

  • Parse file of any size. Memory usage stays low.
  • Use your favorite DOM library: native, jdom, dom4j or xom.
  • Avoid writing boilerplate DOM construction code.


Get Solna from maven central repository



Suppose you have an XML file

    <city id="1">
    <city id="2">

Let's parse it

SolnaParser parser = new SolnaParser();

parser.addHandler("/cities/city", new SolnaHandler<Element>() {
    public void handle(Element elem) {
        // Here goes your code
        // parse, check, save to database etc

InputStream is = ...

Element can be any of these:


Be sure to add it to your classpath.

Why Solna?

###Solna vs DOM

  • Solna has low memory usage. If you can fit the whole DOM tree into your RAM, Solna has not much to offer compared to traditional DOM parsing.
  • You can't use document-wide XPath in Solna.
  • Solna can be slightly slower, because it builds separate DOM trees for each element. Although it can perform better, if you want to skip some parts of the document.
  • Also you can use Solna to gracefully incapsulate DOM construction logic.

###Solna vs SAX/StAX

  • SAX/StAX require you to write unintuitive and tricky handling code. Solna uses DOM.
  • Solna is slower than SAX/StAX, because of DOM construction.

###Solna vs JAXB

  • Solna will not bind values to your POJOs, but it gives you more control on parsing process through DOM manipulation.
  • Solna is slower than JAXB, because of DOM construction.

Behind the scenes

Solna uses StAX to scan XML. When it finds an element you provided handler for, it builds DOM tree for that element. After handling is done DOM tree is thrown away thus freeing the memory.