Note: I am working in Scala.
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 objects to/from XML using XStream:
http://xstream.codehaus.org/index.html
Should be interesting.
TIA,
Chas.