using XML to persist data
Im developing a small application and choosed to use XML instead of MySql because it's smaller and do not require to install a database on the client after software distribution.
The strategy was not keep all data in the XML file, so some parts are shared over folders.
Example:
Let's say I have 10 logins (remember that login can't be repeated) so I have 10 foldes (packges) eah one with it's on xml file about the login info.
So far, it's working very fast.
- - - - - - - - - -
The problem is that I don't know what parser (read/write) to use.
1)
There's a lot over the web, but I'm affraid abaout memory and application size (I'd like to keep it small and readable later) ... so should I use Suns DOM or Stax?
2)
There are simple things I really need: read the xml, change it if needed and display the data. So I need to populate my objects, change them and persist again. Also, I'd like to persist only the nodes that were actualy changed, keeping the unchanged data.
[1048 byte] By [
jsasma] at [2007-11-26 17:53:47]

# 3
Hi,
To parse an XML documents ther are number of techniques are there.
We can use either SAX,DOM,JDOM,DOM4J , XMLBeans,JAXB and
StAX( jdk1.6) ....are there.
Out of these XMLBeans and JAXB are used to generates object represenation out of XML file and try to do operaions using that objects.
Remaining each one has its own advantages and disadvatges,
When you have very large file(memory intensive) then we sholud better gor for SAX , but SAX parser is only to read XML content not to write or modify XML file.
Normally when we want write or update a xml file we use DOM .
# 4
Well, I'll tell you exactly wat I need right now. I've been reading a lot of info and got very confused.
1. The foldes
Folder
.....|_ SubFolder
...........|_ file.xml
* Ineed to read the XML, read it, take the objects I need and disply the with Swing. If there were any changes, save whatever has to be changed.
* Does StaX whort the shot, or is SAX enoug.
tks
# 5
> There's a lot over the web, but I'm affraid abaout
> memory and application size (I'd like to keep it
> small and readable later)
If you are generating XML that is going to use a lot of memory, enough memory that it makes a difference, then you should not have used XML for this application. You should have used a database, which has the advantage that you can extract data from it without having to load the entire dataset into memory.
So let's assume your design is okay and you aren't going to have huge XMLs. In that case use whatever parser is convenient. Quite likely DOM or JDOM would work for you.
# 6
No 1.
First of all, let me apologize. I kinda lost myself on my own explanation! Sorry.
-
No. 2.
.....Yeah, I ended up finding an easy way to read those small xml files (the way I'm trying to keep them so far)...You're right, could be even SAX or DOM. I've choosed SAX by now.
.....The big problem was to understand all those acronyms over the web...beyond learning Java, XML we must remember all those words too. Not an easy task.
-
No. 3.
Can anyone tell me EXACTLY how to use StaX ? Cause I will have to use it later by some xml on demand files i'll need to work with.
-
No. 4.
As I've choosed SAX, how do I change only the tags that matter on the xml file? Is it possible?
-
Thaks a LOT for all the patient people from this forum.... You are the BEST
# 7
> No. 4.
> As I've choosed SAX, how do I change only the tags
> that matter on the xml file? Is it possible?
I have no idea. All you get from SAX is a stream of events. It's going to be really hard to go from that to writing out a modified version of the input. I would have used DOM for this:
- Read the document into a DOM
- Do something to modify the relevant nodes
- Write the DOM out to disk.