Nothing gets printed after insert node
Wednesday, 6 June 2012 · 3 messages
AB
Anupam Bakshi6 Jun 2012 07:53 #
Then how about option 'b' ?
At this point any way forward, any work around will do.
Please let me know if anyone has any suggestion.
What I don't understand is, if I can add nodes why can't I pick those nodes from another resource? Why is this not possible?
But I'm looking for some workaround.
Thanks for your help.
Anupam
MK
M. van Keulen6 Jun 2012 09:38 #
Forgot to send my response to the list:
Quoted text · Anupam Bakshi · 204 lines
-------- Original Message -------- Subject: Re: [basex-talk] Nothing gets printed after insert node Date: Wed, 06 Jun 2012 09:37:25 +0200 From: M. van Keulen <m.vankeulen at utwente.nl> Organization: University of Twente To: Anupam Bakshi <bakshia at yahoo.com> Dear Anupam, You seem to misunderstand the term "update". An update modifies the document in the database. So if you ask for it after that (with doc(...)) you'll get the modified document. In your case: let $s := db:open("BaseX","sample1.xml") let $r := db:open("BaseX","result1.xml") for $m in $s//*:M return insert nodes $r//*:R[@id=$m/@id] into $m modifies the sample1.xml in the database. A subsequent query db:open("BaseX","sample1.xml") would produce <P> <M id="1"> <R id="1"/> </M> <M id="2"> <R id="2"/> </M> <M id="3"/> </P> If you don't want to store the document in the database and modify it, but simply want to generate a *new* intermediary document that is similar to sample1.xml but which includes the desired R-elements, then you don't update anything (the original file stays the same). You can do this with <P>{ let $s := db:open("BaseX","sample1.xml") let $r := db:open("BaseX","result1.xml") for $m in $s//*:M let $o := $r//*:R[@id=$m/@id] return <M>{$m/@*,$m/*,$o}</M> }</P> or by using the transform-expression let $s := db:open("BaseX","sample1.xml") let $r := db:open("BaseX","result1.xml") return copy $new := $s modify ( for $m in $new//*:M return insert nodes $r//*:R[@id=$m/@id] into $m ) return $new Maurice On 06-06-12 08:12, Anupam Bakshi wrote: > Hello Maurice, > Thanks for your response. > How do I communicate the intermediate result (modified document) > between the two queries? > Do I store the intermediate file back in the database? I tried to > store the result of an update in a variable but it said that not > allowed - "Let expression: No updating expression allowed". > So the question is how can I run the first query to update the > document and the second query to retrieve the modified document? > > If someone can point to an example, that will help too. > Best regards, > Anupam > > > ------------------------------------------------------------------------ > *From:* M. van Keulen <m.vankeulen at utwente.nl> > *To:* Anupam Bakshi <bakshia at yahoo.com> > *Cc:* basex-talk at mailman.uni-konstanz.de > *Sent:* Wednesday, June 6, 2012 1:38 AM > *Subject:* Re: [basex-talk] Nothing gets printed after insert node > > Dear Anupam, > > One workaround would be to do it in two queries: one to update your > document, and one to retrieve the modified nodes. > > The problem is not that you can't pick nodes from another resource, > but that XQuery doesn't allow you to update and query inside the same > query. In other words, within one query doing an update means you > can't produce a (query) result, and having a query result means you > can't do any update. > > Regards, > Maurice. > > On 06-06-12 05:53, Anupam Bakshi wrote: >> Then how about option 'b' ? >> At this point any way forward, any work around will do. >> Please let me know if anyone has any suggestion. >> >> What I don't understand is, if I can add nodes why can't I pick those >> nodes from another resource? Why is this not possible? >> >> But I'm looking for some workaround. >> >> Thanks for your help. >> Anupam >> >> >> ------------------------------------------------------------------------ >> *From: * Christian Grün <christian.gruen at gmail.com> >> <mailto:christian.gruen at gmail.com>; >> *To: * Anupam Bakshi <bakshia at yahoo.com> <mailto:bakshia at yahoo.com>; >> *Cc: * <basex-talk at mailman.uni-konstanz.de> >> <mailto:basex-talk at mailman.uni-konstanz.de>; >> *Subject: * Re: [basex-talk] Nothing gets printed after insert node >> *Sent: * Wed, Jun 6, 2012 12:24:18 AM >> >> > I'm interested in 'a'. >> > The two files are in basex, I need to write a query that will >> return the >> > modified nodes at run time. >> >> Due to the nature of the XQuery Update Specification, that's generally >> not possible. Sorry for that. >> >> >> > From: Christian Grün <christian.gruen at gmail.com>; >> > To: Anupam Bakshi <bakshia at yahoo.com>; >> > Cc: basex-talk at mailman.uni-konstanz.de >> > <basex-talk at mailman.uni-konstanz.de>; >> > Subject: Re: [basex-talk] Nothing gets printed after insert node >> > Sent: Tue, Jun 5, 2012 9:09:06 PM >> > >> > Are you mostly interested in >> > >> > a) updating your data, and returning the modified node(s) as query >> result, >> > or >> > b) finding the correct updating query to modify your data? >> > ___________________________ >> > >> > > Here is what I actually want to do. Maybe someone can suggest a >> > > straightforward way. >> > > >> > > File : sample1.xml >> > > <P> >> > > <M id="1"/> >> > > <M id="2"/> >> > > <M id="3"/> >> > > </P> >> > > >> > > File: result1.xml >> > > <Q> >> > > <R id="1"/> >> > > <R id="2"/> >> > > </Q> >> > > >> > > Desired output : >> > > <P> >> > > <M id="1"> >> > > <R id="1"/> >> > > </M> >> > > <M id="2"> >> > > <R id="2"/> >> > > </M> >> > > <M id="3"/> >> > > </P> >> > > >> > > So insert the node from 2nd file into 1st where the ids match. >> > > >> > > Thanks, >> > > Amupam >> > > >> > > ________________________________ >> > > From: Christian Grün <christian.gruen at gmail.com> >> > > To: Anupam Bakshi <bakshia at yahoo.com> >> > > Cc: basex-talk at mailman.uni-konstanz.de >> > > Sent: Tuesday, June 5, 2012 12:02 PM >> > > Subject: Re: [basex-talk] Nothing gets printed after insert node >> > > >> > >> Unfortunately I did not see how I can return the value into a >> variable >> > >> for >> > >> further processing. >> > >> Is there some other way to do it? >> > > >> > > Did you already try db:output()? >> > > >> > > >> > > -- > ---------------------------------------------------------------------- > Dr.Ir. M. van Keulen - Associate Professor, Data Management Technology > Univ. of Twente, Dept of EEMCS, POBox 217, 7500 AE Enschede, Netherlands > Email:m.vankeulen at utwente.nl <mailto:m.vankeulen at utwente.nl>, Phone: +31 534893688, Fax: +31 534892927 > Room: ZI 3039, WWW:http://www.cs.utwente.nl/~keulen > > -- ---------------------------------------------------------------------- Dr.Ir. M. van Keulen - Associate Professor, Data Management Technology Univ. of Twente, Dept of EEMCS, POBox 217, 7500 AE Enschede, Netherlands Email:m.vankeulen at utwente.nl, Phone: +31 534893688, Fax: +31 534892927 Room: ZI 3039, WWW:http://www.cs.utwente.nl/~keulen -- ---------------------------------------------------------------------- Dr.Ir. M. van Keulen - Associate Professor, Data Management Technology Univ. of Twente, Dept of EEMCS, POBox 217, 7500 AE Enschede, Netherlands Email: m.vankeulen at utwente.nl, Phone: +31 534893688, Fax: +31 534892927 Room: ZI 3039, WWW: http://www.cs.utwente.nl/~keulen
AB
Anupam Bakshi6 Jun 2012 14:22 #
Hello Maurice, Christian,
I'm grateful to you for providing me help. This is exactly what I needed. Thanks a lot.
Now I can move forward with the application development.
Best regards,
Anupam
________________________________
From: M. van Keulen <m.vankeulen at utwente.nl>
To: Anupam Bakshi <bakshia at yahoo.com>
Sent: Wednesday, June 6, 2012 3:37 AM
Subject: Re: [basex-talk] Nothing gets printed after insert node
Dear Anupam,
You seem to misunderstand the term "update". An update modifies the document in the database. So if you ask for it after that (with doc(...)) you'll get the modified document. In your case:
let $s := db:open("BaseX","sample1.xml")Quoted text · M. van Keulen · 5 lines
>let $r := db:open("BaseX","result1.xml") >for $m in $s//*:M >return > insert nodes $r//*:R[@id=$m/@id] into $m >
modifies the sample1.xml in the database. A subsequent query db:open("BaseX","sample1.xml") would produce
<P>Quoted text · M. van Keulen · 9 lines
> <M id="1"> > <R id="1"/> > </M> > <M id="2"> > <R id="2"/> > </M> > <M id="3"/> ></P> >
If you don't want to store the document in the database and modify it, but simply want to generate a *new* intermediary document that is similar to sample1.xml but which includes the desired R-elements, then you don't update anything (the original file stays the same). You can do this with
Quoted text · M. van Keulen · 8 lines
<P>{ >let $s := db:open("BaseX","sample1.xml") >let $r := db:open("BaseX","result1.xml") >for $m in $s//*:M >let $o := $r//*:R[@id=$m/@id] >return <M>{$m/@*,$m/*,$o}</M> >}</P> >
or by using the transform-expression
let $s := db:open("BaseX","sample1.xml")Quoted text · M. van Keulen · 10 lines
>let $r := db:open("BaseX","result1.xml") >return >copy $new := $s >modify ( > for $m in $new//*:M > return > insert nodes $r//*:R[@id=$m/@id] into $m >) >return $new >
Maurice
Quoted text · Anupam Bakshi · 1 line
On 06-06-12 08:12, Anupam Bakshi wrote:
Hello Maurice,
Quoted text · M. van Keulen · 26 lines
> Thanks for your response. > How do I communicate the intermediate result (modified document) between the two queries? > > Do I store the intermediate file back in the database? I tried to store the result of an update in a variable but it said that not allowed - "Let expression: No updating expression allowed". > So the question is how can I run the first query to update the document and the second query to retrieve the modified document? > > > If someone can point to an example, that will help too. >Best regards, >Anupam > > > > > >________________________________ > From: M. van Keulen <m.vankeulen at utwente.nl> >To: Anupam Bakshi <bakshia at yahoo.com> >Cc: basex-talk at mailman.uni-konstanz.de >Sent: Wednesday, June 6, 2012 1:38 AM >Subject: Re: [basex-talk] Nothing gets printed after insert node > > >Dear Anupam, > >One workaround would be to do it in two queries: one to
update your document, and one to retrieve the modified nodes.
Quoted text · M. van Keulen · 2 lines
> >The problem is not that you can't pick nodes from
another resource, but that XQuery doesn't allow you to update and query inside the same query. In other words, within one query doing an update means you can't produce a (query) result, and having a query result means you can't do any update.
Quoted text · M. van Keulen · 7 lines
> >Regards, >Maurice. > >On 06-06-12 05:53, Anupam Bakshi wrote: >Then how about option 'b' ? >>At this point any way forward, any work
around will do.
Quoted text · M. van Keulen · 1 line
>>Please let me know if anyone has any
suggestion.
Quoted text · M. van Keulen · 2 lines
>> >>What I don't understand is, if I can add
nodes why can't I pick those nodes from another resource? Why is this not possible?
Quoted text · M. van Keulen · 31 lines
>> >>But I'm looking for some workaround. >> >>Thanks for your help. >>Anupam >> >> >> >>________________________________ >> From: Christian Grün <christian.gruen at gmail.com>; >>To: Anupam Bakshi <bakshia at yahoo.com>; >>Cc: <basex-talk at mailman.uni-konstanz.de>; >>Subject: Re: [basex-talk] Nothing gets printed after insert node >>Sent: Wed, Jun 6, 2012 12:24:18 AM >> >> >>> I'm interested in 'a'. >>> The two files are in basex, I need to write a query that will return the >>> modified nodes at run time. >> >>Due to the nature of the XQuery Update Specification, that's generally >>not possible. Sorry for that. >> >> >>> From: Christian Grün <christian.gruen at gmail.com>; >>> To: Anupam Bakshi <bakshia at yahoo.com>; >>> Cc: basex-talk at mailman.uni-konstanz.de >>> <basex-talk at mailman.uni-konstanz.de>; >>> Subject: Re: [basex-talk] Nothing
gets printed after insert node
Quoted text · M. van Keulen · 5 lines
>>> Sent: Tue, Jun 5, 2012 9:09:06 PM >>> >>> Are you mostly interested in >>> >>> a) updating your data, and
returning the modified node(s) as query
Quoted text · M. van Keulen · 3 lines
result, >>> or >>> b) finding the correct updating
query to modify your data?
Quoted text · M. van Keulen · 3 lines
>>> ___________________________ >>> >>> > Here is what I actually want
to do. Maybe someone can suggest a
Quoted text · M. van Keulen · 27 lines
>>> > straightforward way. >>> > >>> > File : sample1.xml >>> > <P> >>> > <M id="1"/> >>> > <M id="2"/> >>> > <M id="3"/> >>> > </P> >>> > >>> > File: result1.xml >>> > <Q> >>> > <R id="1"/> >>> > <R id="2"/> >>> > </Q> >>> > >>> > Desired output : >>> > <P> >>> > <M id="1"> >>> > <R id="1"/> >>> > </M> >>> > <M id="2"> >>> > <R id="2"/> >>> > </M> >>> > <M id="3"/> >>> > </P> >>> > >>> > So insert the node from 2nd
file into 1st where the ids match.
Quoted text · M. van Keulen · 5 lines
>>> > >>> > Thanks, >>> > Amupam >>> > >>> >
________________________________
Quoted text · M. van Keulen · 4 lines
>>> > From: Christian Grün <christian.gruen at gmail.com> >>> > To: Anupam Bakshi <bakshia at yahoo.com> >>> > Cc: basex-talk at mailman.uni-konstanz.de >>> > Sent: Tuesday, June 5, 2012
12:02 PM
Quoted text · M. van Keulen · 1 line
>>> > Subject: Re: [basex-talk]
Nothing gets printed after insert node
Quoted text · M. van Keulen · 2 lines
>>> > >>> >> Unfortunately I did not
see how I can return the value into a variable
Quoted text · M. van Keulen · 3 lines
>>> >> for >>> >> further processing. >>> >> Is there some other way to
do it?
Quoted text · M. van Keulen · 2 lines
>>> > >>> > Did you already try
db:output()?Quoted text · M. van Keulen · 5 lines
>>> > >>> > >> > >--
---------------------------------------------------------------------- Dr.Ir. M. van Keulen - Associate Professor, Data Management Technology Univ. of Twente, Dept of EEMCS, POBox 217, 7500 AE Enschede, Netherlands Email: m.vankeulen at utwente.nl, Phone: +31 534893688, Fax: +31 534892927 Room: ZI 3039, WWW: http://www.cs.utwente.nl/~keulen
Quoted text · M. van Keulen · 2 lines
> >
--
---------------------------------------------------------------------- Dr.Ir. M. van Keulen - Associate Professor, Data Management Technology Univ. of Twente, Dept of EEMCS, POBox 217, 7500 AE Enschede, Netherlands Email: m.vankeulen at utwente.nl, Phone: +31 534893688, Fax: +31 534892927 Room: ZI 3039, WWW: http://www.cs.utwente.nl/~keulen
Written for BaseX 7.2. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery