Hello Manish,
please always reply to the list, so others can also benefit from questions and answers.
String query = "db:add("db","xmlFile")";
will certainly not work, this will throw a java error due to the ". This should work:
String query = "db:add('db','xmlFile')";
As I already suggested (multiple times) on StackOverflow, you will have to build and modify the document within BaseX using XQuery Update. This way, the XML file can be kept in main memory and later be added to the database. Please read up in our documentation about XQuery Updates.
Cheers, Dirk
On 30/07/14 11:37, manish payasi wrote:
Thanks Dirk,
I am trying to write like String query = "db:add("db","xmlFile")"; where xmlFile is string variable which has xml file name, but it is throwing some syntax error (like Syntax error on tokens, delete these tokens for both the arguments) .
Another thing is that in second argument we are passing the xml file which is still coming from disk which we don't want it rather than i want create the xml file dynamically in java and store this file directly into database.
Thanks and Regards manish payasi.
On Tue, Jul 29, 2014 at 6:29 PM, Dirk Kirsten dk@basex.org wrote:
Hi Manish,
You might want to take a look at our java examples here : https://docs.basex.org/wiki/Java_Examples
So to simply execute an XQuery and using db:add() (see https://docs.basex.org/wiki/Database_Module#db:add) to add to the database would look something like that:
Context context = new Context(); String query = "db:add("your-database", <xml>here goes your
xml</xml>, "myfile.xml") QueryProcessor proc = new QueryProcessor(query, context); proc.execute(); proc.close(); context.close();
the second argument of db:add() is an item(), so you can also dynamically generate an XML element here.
Cheers, Dirk
On 29/07/14 14:46, manish payasi wrote:
How to create xml file dynamically in java and store into BaseX database 'db'. That means it shouldn't not be created into my disk(my system) but
it
should be directly created(store) into database 'db' ?????
Please give me some better solution.
-- Dirk Kirsten, BaseX GmbH, http://basex.org |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22
basex-talk@mailman.uni-konstanz.de