I'm wondering if anyone here has experience working with a native XML database, and at the same time I'm looking for a sanity check on my idea. There are many threads like this, but this one is mine.
One of my tasks at work is to convert a set of M XML files into a set of N CSV files. We get the M XML files from a component not under our control, we have to output N CSV files to another component not (very much) under our control. The mapping from source to output is not 1-to-1; its full complexity is yet to be determined.
So, not a difficult task, but still one that requires consideration. My first thought was pretty much the same as this one:
My second thought was to just run a SAX parser over the XML files, parse XML elements one at a time and write to output as appropriate. But it turns out that would be inconvenient too, because in writing out the CSVs I have to sometimes reference parent or child elements. I may even have to reference other XML files. So I would in essence be manually creating an in-memory model of my data, that I'd then be writing to disk.
And so after a bit of Googling, it dawned on me: I already have a data format. I just need to store it efficiently and query it. Enter the native XML databases, and XQuery. The top three Google hits, apart from the Wikipedia entry, are BaseX, eXist-db and Oracle XML DB.
I started with BaseX and have been pretty pleased with the results so far. I fed it 100 MB of data and it parsed it and indexed it in no time flat. All my queries return in less than one second. (Tomorrow I'll be testing it with some larger files to see how it copes.) Most importantly, I can now effortlessly run queries of the form
A thing of beauty. It should work well, after all, this is what XQuery was designed for. But while the idea seems good--this is where you fine folk yell at me if I'm wrong--the implementation fills me with concern. BaseX is apparently actively developed by just one person, and while I'm sure they're competent and have nothing but good intentions, it's still just one person. Its native bindings to Java are a joke. That would be OK, since technically I should be using the XQuery API for Java anyway. Except, the XQJ API for BaseX is also developed by what appears to be a small team, at http://xqj.net/. What do you know, they also develop the XQJ API for eXist-db and Sedna; guess I have no choice but to trust them.
Over on the other side of the fence, eXist-db are apparently "preparing the 2.0 release" and so can't be bothered with small things like non-broken links to their JavaDoc. Meanwhile, Oracle go into the opposite direction and provide 100 pages of documentation on how to run a simple XQuery. I guess too much is better than too little; of course, one needs to ask, is such a heavyweight solution even necessary?
So. Anyone know which of these possible solutions is the best? Any recommendations?
One of my tasks at work is to convert a set of M XML files into a set of N CSV files. We get the M XML files from a component not under our control, we have to output N CSV files to another component not (very much) under our control. The mapping from source to output is not 1-to-1; its full complexity is yet to be determined.
So, not a difficult task, but still one that requires consideration. My first thought was pretty much the same as this one:
But that's a lot of work. It's error prone and verbose. And why would I manually create a new format to store data that already has an implied format, namely its XML structure? Crazy talk.[url=http:/civis/viewtopic.php?p=23678412#p23678412:2innxfoo said:Ravensroke[/url]":2innxfoo]1. Make a database with tables that sort of match your xml structure.
2. Parse XML into java objects
3. Bulk load data into database with the database framework of your choice (plain JDBC, JDBC templates, Hibernate)
4. Use sql queries to query your data
5. Profit.
My second thought was to just run a SAX parser over the XML files, parse XML elements one at a time and write to output as appropriate. But it turns out that would be inconvenient too, because in writing out the CSVs I have to sometimes reference parent or child elements. I may even have to reference other XML files. So I would in essence be manually creating an in-memory model of my data, that I'd then be writing to disk.
And so after a bit of Googling, it dawned on me: I already have a data format. I just need to store it efficiently and query it. Enter the native XML databases, and XQuery. The top three Google hits, apart from the Wikipedia entry, are BaseX, eXist-db and Oracle XML DB.
I started with BaseX and have been pretty pleased with the results so far. I fed it 100 MB of data and it parsed it and indexed it in no time flat. All my queries return in less than one second. (Tomorrow I'll be testing it with some larger files to see how it copes.) Most importantly, I can now effortlessly run queries of the form
Code:
for $thing in /collection//thing return ($thing/@ID, $thing/text(), $thing/../@parentID)
A thing of beauty. It should work well, after all, this is what XQuery was designed for. But while the idea seems good--this is where you fine folk yell at me if I'm wrong--the implementation fills me with concern. BaseX is apparently actively developed by just one person, and while I'm sure they're competent and have nothing but good intentions, it's still just one person. Its native bindings to Java are a joke. That would be OK, since technically I should be using the XQuery API for Java anyway. Except, the XQJ API for BaseX is also developed by what appears to be a small team, at http://xqj.net/. What do you know, they also develop the XQJ API for eXist-db and Sedna; guess I have no choice but to trust them.
Over on the other side of the fence, eXist-db are apparently "preparing the 2.0 release" and so can't be bothered with small things like non-broken links to their JavaDoc. Meanwhile, Oracle go into the opposite direction and provide 100 pages of documentation on how to run a simple XQuery. I guess too much is better than too little; of course, one needs to ask, is such a heavyweight solution even necessary?
So. Anyone know which of these possible solutions is the best? Any recommendations?