Reputation: 3707
Ok, so I am still relatively new to Java and I'm making pretty good progress. My task is this:
My question is, what is the best way to store this data in Java so that I can sort through it easily? The data portion of my XML looks like this:
<RawData>
<item value="1" anothervalue="2" yetanothervalue="3"/>
<item value="4" anothervalue="5" yetanothervalue="6"/>
<item value="7" anothervalue="8" yetanothervalue="9"/>
</RawData>
I have no problem using XPath and SimpleXPathEngine to retrieve specific values from the XML. But I would really love to be able to store it in some sort of ResultSet type structure so that I could easily retrieve and manipulate it. I've used ResultSet with SQL queries so I'm familiar and comfortable with it, however, I'm not sure how to use it outside of an actual DB connection and query. What would be the best way to handle this?
Thanks in advance!
Upvotes: 1
Views: 495
Reputation: 597056
If the document is not that big, you can use a DOM parser to get all data in-memory. That's either org.w3c.dom
, dom4j or jdom
Upvotes: 4
Reputation: 486
You can store the data in a memory-only database. hsqldb supports this functionality.
Upvotes: 2
Reputation: 30216
Well since your data seems simple and regular I'd personally use JAXB - you can either create the classes by hand or use some tool to generate them from the XML schema.
That way you can easily work with a List of your classes and can use your usual java to get at the data or manipulate it, also you can easily ignore fields you don't need in your java representation so your classes will only cover those parts of the XML file you're really interested in.
Upvotes: 2