Write & Read XML with JAVA, any libraries advised …?
I want to store & retrieve a huge amount of parameters using XML format.
The idea is to wrote my own store/retrieve functions.
Any lib advised from your experiences ?
Should I use DOM, SAX ?
I want to keep that simple and light.
Apparently, sadam.rapidXML seems very fine.
the whole package by Siska is provided with a sadamLib.jar, which would mean I can use it in my JAVA Core.
I added the library as an external one in Eclipse, I imported it in my java source… then ?
is there a doc somewhere to use this precious rapidXML tool ?
the documentation for all of my externals come as help files and references, which (once copied to the appropriate Cycling ’74 folders) should load in Max.
Creating docs is actually always a weird task as one should describe something which he/she basically already knows, however, the docs should make sense to users who read them without any prior knowledge on the expected behaviour of the object. Therefore it is possible that my documentation is not complete, or that they don’t explain well how to use the externals.
If you feel that something is missing from the docs, or that some features are not clear enough, please let me know so that I could update them.
just another short note regarding my XML parsers. Since it’s not clear what you exactly want to process, I can only say a few things in general.
Regarding the question of DOM vs. SAX (in general), the main difference is that SAX parsers will parse an XML ‘on the fly’, while DOM parsers will build a so-called ‘DOM tree’ based on the XML (the DOM tree is a logical representation of the XML itself) which they would store in the memory. This means that if you want to modify your data (or if you want to access the same XML multiple times) you can only use a DOM-like approach. The same applies if you want to build your own XML files, as you won’t be able to create an XML using SAX.
The following applies only if you really consider using my objects. If speed matters, I would go with
sadam.rapidXML, which is by far the fastest of all three objects (when I tested them,
sadam.rapidXML was at least 5 times faster than
sadam.sax and at least 10 times faster than
sadam.dom), and it’s even faster than the native Java XML libraries themselves (actually, if speed REALLY matters, I would move my whole core to C and use RapidXML natively, which is probably the fastest XML processor that I ever met). On the other hand, unfortunately RapidXML is not fully W3C compliant (basically because !DOCTYPE declarations are ignored and it will allow you to create more than one so-called ‘root element’ — although as far as I remember, I fixed the latter in some extent), therefore if ‘W3C compliantness’ matters more than speed, I would go with one of my MXJ-based parsers. However, as already mentioned, if you are doing your core in Java anyway and you choose to go with Java-based parsers instead of RapidXML, I would recommend you to use the legacy Java XML tools that are already present in Java (for instance, to make your project less dependent on third-party software).
Hope this helps,
Of course it helps a lot, Adam :)
I’m designing a system for which I need to save some datas in kind of presets (called map, because my system is a 3D virtual world)
Basically, I won’t go to global MaxObject or custom classes serialization kind of things because I’d prefer to keep the control over read/write processes.
Then, I need to store all values from an hashMap in XML, and to read an XML, exploding its values into the hashMap and instantiating my world.
It is a really basic stuff and, considering your informations, I probably would go, will go to org.w3C.dom package.
Indeed, this is a one shot read & store operation.
It won’t be used while playing or even composing into this 3D sequencer.
I’m currently working on a patch using the sadam.rapidXML object. Everything seems to work fine – there’s just one little thing.
Before I can do the XML-parsing I have to call a "read" message to tell the object where the XML-file is located.
What I would like to know is how to find out when this "read" procedure is finished so that I can start my parsing programmatically.
Thanks in advance