Thanks, Christian, for your very helpful reply. Please don't interpret my comments as complaints of any sort! I understand fully how difficult it is to keep up with documentation. I am only identifying those issues that I encounter in the hopes that they'll make it onto your priorities list. The squeaky wheel gets the grease, as we say.
I think that BaseX as an embedded document database and persistence layer (with XStream) could be a very lightweight and portable but powerful system. I'm headed in that direction and am happy to contribute back any code. The only problem is that I am not a Java programmer -- I work in Scala. But if someone else on the list is interested, they could easily do the same with Java. I'd love to see an XStream/BaseX module for the Play! web framework.
I think your code below should say CreateDB rather than Create, as Create takes a Parser object rather than two strings. I tested with CreateDB and it works beautifully. Thank you very much! I can now convert objects to XML with XStream, store them in BaseX, retrieve them, and create new objects from the XML with XStream. All the basics of persistence are there.
I'll play around a bit more and will keep you posted. I found a similar project using XStream called Xbird, and I'm going to try to steal some of their ideas:
http://code.google.com/p/xbird/
I've also downloaded 6.1.9. Nice work! Are the JavaDocs posted somewhere or do I need to generate them?
Thanks for all your help.
Chas.
On 07/08/2010 1:40 PM, Christian Grün wrote:
Hi Chas,
regarding the storage of your databases, you can change the location by modifying ".basex" in your home directory or using the GUI (Options -> Preferences).
regarding the update of your database, I would recommend to use XQuery Update and insert new documents as fragments. You could start off creating an empty database with a single root node, and add new fragments via XQuery, as shown below:
basex -c "create db test<xml/>; xquery insert node<person/> into /xml; xquery /"
new Create("db", "<xml/>").execute(context); new XQuery("insert node<sub/> into /xml").execute(context); new XQuery("/").execute(context, System.out);
Note that the quoted examples are based on the syntax of the latest version of BaseX (6.1.9 and following), so it might slightly differ from the BaseX 6.1 (the next public release is to be expected soon).
You might think about getting the "examples" package from BaseX, which includes numerous snippets for embedding BaseX into your own code:
https://svn.uni-konstanz.de/dbis/basex/trunk/
No doubt it would be preferrable to have it all included in a documentation, but we currently lack the time in putting more work in that.
Last but not least: it's a nice idea to use BaseX as a persistence layer. We had some thoughts on this before – but not more than that – so feedback is welcome.
Hope this helps, Christian
I want to be able to create new XML documents based on input from a Web-based form, then add them to a Collection in an embedded instance of BaseX programmatically.
So if I have a collection called "Persons" and XML in memory thus:
<person id="df802f63-f5b9-4b28-951e-aa2c8d7220dd"> <name>Chas</name> <gender>Male</gender> </person>
(or as a String, if that's necessary -- Scala allows inline XML).
I want this db stored not in my home directory, but in WEB-INF/db.
So how do I use CreateDB(input, name) to create the db where I want it? What do I provide for the input? Must I have an XML file already? What is the relationship between that file and the DB, and how does this differ from a collection? Can anyone point me to a spot in the documentation where this is covered? All I can find are examples and they are confusing to me.
Once I have a DB open (and maybe a collection), I want to add an XML document directly from code, thus:
val xml =<person><name>Chas</name></person>
or maybe
val xml = "<person><name>Chas</name></person>"
then
Add(xml).execute(context)
I've tried this but the XML disappears. How do I put this in the correct DB and collection?
It seems pretty straightforward to use the console or the GUI, but the documentation on embedded use is pretty sparse. Is anyone else using BaseX in embedded mode? Is there documentation somewhere (or more examples) that I've missed?
Thanks. I am thinking about using BaseX for persistence by converting
t> objects to/from XML using XStream:
http://xstream.codehaus.org/index.html
Should be interesting.
TIA,
Chas. _______________________________________________ BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk