adding document (as string) to collection
Monday, 1 March 2010 · 4 messages · last reply 2 Mar 2010
TW
Travis Webb1 Mar 2010 07:35 #
Everyone,
Here's my situation:
I'm using XQJ. I have an xml document stored as a java string, and I want to store this into an xquery collection. I see no way to do this without using the BaseX-specific libraries. I've looked everywhere, and the only thing I've found that's close is MonetDB's add-doc() function, but that takes a url as an argument, not a string. I want to do something like: insert node $document into collection("test"). Obviously this doesn't work because collections are sequences.
Any info is appreciated.
-tjw
CG
Christian Grün1 Mar 2010 18:04 #
Dear Travis,
it's true, unfortunately XQuery Update does not allow to add document nodes to collections/databases. One of the reasons is that the document node gets lost by the update, i.e. if your document looks as follows..
test.xml: <xml/>
..the following two expressions will do the same:
– insert node doc('test.xml') into …
– insert node <xml/> into …
If you want to stick with XQJ and XQuery (Update), the easiest approach is to define one document root and add all new documents as children:
– insert node <xml>new document</xml> into /root
As other users had similar requests to yours, we are interested in your own suggestions how you would like to see this issue fixed (e.g., by adding some XQuery functions like basex:add("...") and
basex:delete("...")).
Hope this helps,
Christian
Quoted text · Travis Webb · 12 lines
On Mon, Mar 1, 2010 at 6:35 AM, Travis Webb <tjwebb at vt.edu> wrote: > Everyone, > Here's my situation: > I'm using XQJ. I have an xml document stored as a java string, and I want to > store this into an xquery collection. I see no way to do this without using > the BaseX-specific libraries. I've looked everywhere, and the only thing > I've found that's close is MonetDB's add-doc() function, but that takes a > url as an argument, not a string. I want to do something like: > insert node $document into collection("test"). Obviously this doesn't work > because collections are sequences. > Any info is appreciated. > -tjw
___________________________
Christian Gruen
Universitaet Konstanz
Department of Computer & Information Science
D-78457 Konstanz, Germany
Tel: +49 (0)7531/88-4449, Fax: +49 (0)7531/88-3577
http://www.inf.uni-konstanz.de/~gruen
TW
Travis Webb1 Mar 2010 22:57 #
Christian,
Thank you for your response. I am using a collection, and do not want to use a single document. Is there any way I can add documents to it? I'm looking through the basex docs and see the "Add" class, but I don't see how I can do this on a server? It looks like Add can only operate on a local database. I'm looking for any solution. Thanks.
-tjw
On Mon, Mar 1, 2010 at 12:04 PM, Christian Grün
<christian.gruen at gmail.com>wrote:
Quoted text · Christian Grün · 55 lines
> Dear Travis, > > it's true, unfortunately XQuery Update does not allow to add document > nodes to collections/databases. One of the reasons is that the > document node gets lost by the update, i.e. if your document looks as > follows.. > > test.xml: <xml/> > > ..the following two expressions will do the same: > > – insert node doc('test.xml') into … > – insert node <xml/> into … > > If you want to stick with XQJ and XQuery (Update), the easiest > approach is to define one document root and add all new documents as > children: > > – insert node <xml>new document</xml> into /root > > As other users had similar requests to yours, we are interested in > your own suggestions how you would like to see this issue fixed (e.g., > by adding some XQuery functions like basex:add("...") and > basex:delete("...")). > > Hope this helps, > Christian > > > > On Mon, Mar 1, 2010 at 6:35 AM, Travis Webb <tjwebb at vt.edu> wrote: > > Everyone, > > Here's my situation: > > I'm using XQJ. I have an xml document stored as a java string, and I want > to > > store this into an xquery collection. I see no way to do this without > using > > the BaseX-specific libraries. I've looked everywhere, and the only thing > > I've found that's close is MonetDB's add-doc() function, but that takes a > > url as an argument, not a string. I want to do something like: > > insert node $document into collection("test"). Obviously this doesn't > work > > because collections are sequences. > > Any info is appreciated. > > -tjw > > ___________________________ > > Christian Gruen > Universitaet Konstanz > Department of Computer & Information Science > D-78457 Konstanz, Germany > Tel: +49 (0)7531/88-4449, Fax: +49 (0)7531/88-3577 > http://www.inf.uni-konstanz.de/~gruen >
CG
Christian Grün2 Mar 2010 13:22 #
Dear Travis,
if you want to use the ADD command with the c/s architecture, you could specify the XML string as argument, or specify a URL to your document.
Best,
Christian
Quoted text · Travis Webb · 8 lines
On Mon, Mar 1, 2010 at 9:58 PM, Travis Webb <tjwebb at vt.edu> wrote: > Christian, > Thank you for your response. I am using a collection, and do not want to use > a single document. Is there any way I can add documents to it? I'm looking > through the basex docs and see the "Add" class, but I don't see how I can do > this on a server? It looks like Add can only operate on a local database. > I'm looking for any solution. Thanks. > -tjw
___________________________
Christian Gruen
Universitaet Konstanz
Department of Computer & Information Science
D-78457 Konstanz, Germany
Tel: +49 (0)7531/88-4449, Fax: +49 (0)7531/88-3577
http://www.inf.uni-konstanz.de/~gruen
Written for BaseX 6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery