Converting String to node inside XQuery
Tuesday, 26 April 2011 · 9 messages
CG
Sony,
please provide complete queries, otherwise it's difficult to give constructive feedback (e.g.: $entry isn't specified anywhere, etc).
Christian
Quoted text · Sony Vijay · 29 lines
On Tue, Apr 26, 2011 at 3:59 PM, Sony Vijay <sony.vibh at gmail.com> wrote: > Hi, > I am wondering if there is a way to convert a String into a Node within > XQuery. > For example, consider the xquery > let $node := > copy $c := > <entry> > <title>entry title</title> > <content>entry content</content> > </entry> > modify ( > return replace value of node $entry/title with 'new entry title', > return replace value of node $entry/content with 'new entry content' > ) > return $c > > return replace node doc('doc1')/entry with $c > The above xquery throws the error: [XPTY0019] Context node required for > entry; xs:string found. How do I fix this ? > Thanks, > Sony > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > >
CG
…still incorrect; "return" before "replace" doesn't make sense. C.
Quoted text · Sony Vijay · 59 lines
On Tue, Apr 26, 2011 at 4:58 PM, Sony Vijay <sony.vibh at gmail.com> wrote: > Hi Christian, > The complete query is: > let $node := > copy $c := > <entry> > <title>entry title</title> > <content>entry content</content> > </entry> > modify ( > return replace value of node $c/title with 'new entry title', > return replace value of node $c/content with 'new entry content' > ) > return $c > return replace node doc('doc1')/entry with $node > Note: doc1 is a document in the database with 'entry' as the root element. > - Sony > On Tue, Apr 26, 2011 at 10:40 AM, Christian Grün <christian.gruen at gmail.com> > wrote: >> >> Sony, >> >> please provide complete queries, otherwise it's difficult to give >> constructive feedback (e.g.: $entry isn't specified anywhere, etc). >> >> Christian >> >> >> On Tue, Apr 26, 2011 at 3:59 PM, Sony Vijay <sony.vibh at gmail.com> wrote: >> > Hi, >> > I am wondering if there is a way to convert a String into a Node within >> > XQuery. >> > For example, consider the xquery >> > let $node := >> > copy $c := >> > <entry> >> > <title>entry title</title> >> > <content>entry content</content> >> > </entry> >> > modify ( >> > return replace value of node $entry/title with 'new entry title', >> > return replace value of node $entry/content with 'new entry content' >> > ) >> > return $c >> > >> > return replace node doc('doc1')/entry with $c >> > The above xquery throws the error: [XPTY0019] Context node required for >> > entry; xs:string found. How do I fix this ? >> > Thanks, >> > Sony >> > >> > _______________________________________________ >> > BaseX-Talk mailing list >> > BaseX-Talk at mailman.uni-konstanz.de >> > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> > >> > > >
SV
Sony Vijay26 Apr 2011 18:05 #
Hi,
I am wondering if there is a way to convert a String into a Node within XQuery.
For example, consider the xquery
let $node :=
copy $c :=
<entry>
<title>entry title</title>
<content>entry content</content>
</entry>
modify (
return replace value of node $entry/title with 'new entry title',
return replace value of node $entry/content with 'new entry content'
)
return $creturn replace node doc('doc1')/entry with $c
The above xquery throws the error: [XPTY0019] Context node required for entry; xs:string found. How do I fix this ?
Thanks,
Sony
LW
Hi Sony,
Quoted text · Sony Vijay · 13 lines
Am 26.04.2011 18:38, schrieb Sony Vijay: > let $node := > copy $c := > <entry> > <title>entry title</title> > <content>entry content</content> > </entry> > modify ( > return replace value of node $c//title with 'new entry title', > return replace value of node $c//content with 'new entry content' > ) > return $c > replace node doc('doc1')/entry with $node
Please check beforehand that your queries don't contain obvious syntax errors like the one above. This can be easily accomplished by copy-pasting them into the BaseX GUI [1], which highlights errors quite nicely.
Quoted text · Sony Vijay · 1 line
> This does not work.
Try deleting both 'return' keywords in the 'modify' clause and adding one at the beginning of the last line.
And please keep in mind that this mailing list should be primarily about BaseX, not XQuery syntax.
HTH,
Leo
__________
[1] http://basex.org/products/download/all-downloads/
SV
Hi Christian,
The complete query is:
let $node :=
copy $c :=
<entry>
<title>entry title</title>
<content>entry content</content>
</entry>
modify (
return replace value of node $c/title with 'new entry title',
return replace value of node $c/content with 'new entry content'
)
return $c
return replace node doc('doc1')/entry with $nodeNote: doc1 is a document in the database with 'entry' as the root element.
- Sony
On Tue, Apr 26, 2011 at 10:40 AM, Christian Grün
<christian.gruen at gmail.com>wrote:
Quoted text · Christian Grün · 38 lines
> Sony, > > please provide complete queries, otherwise it's difficult to give > constructive feedback (e.g.: $entry isn't specified anywhere, etc). > > Christian > > > On Tue, Apr 26, 2011 at 3:59 PM, Sony Vijay <sony.vibh at gmail.com> wrote: > > Hi, > > I am wondering if there is a way to convert a String into a Node within > > XQuery. > > For example, consider the xquery > > let $node := > > copy $c := > > <entry> > > <title>entry title</title> > > <content>entry content</content> > > </entry> > > modify ( > > return replace value of node $entry/title with 'new entry title', > > return replace value of node $entry/content with 'new entry content' > > ) > > return $c > > > > return replace node doc('doc1')/entry with $c > > The above xquery throws the error: [XPTY0019] Context node required for > > entry; xs:string found. How do I fix this ? > > Thanks, > > Sony > > > > _______________________________________________ > > BaseX-Talk mailing list > > BaseX-Talk at mailman.uni-konstanz.de > > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > > > > >
SV
Yes, I tried the query without the return earlier. I saw a syntax error: [XPST0003] Expecting 'where', 'order' or 'return' expression.
I return $c in my query but I still see the error. Looking at the error, I guessed that when a transform function is used in a query, return is required to replace.
Also, I am using two return statements inside the modify function. I am not sure if that is allowed. In any event, is there a way to update multiple nodes at the same time with or without using modify.
Thanks,
Sony
On Tue, Apr 26, 2011 at 11:02 AM, Christian Grün
<christian.gruen at gmail.com>wrote:
Quoted text · Christian Grün · 70 lines
> …still incorrect; "return" before "replace" doesn't make sense. > C. > > > On Tue, Apr 26, 2011 at 4:58 PM, Sony Vijay <sony.vibh at gmail.com> wrote: > > Hi Christian, > > The complete query is: > > let $node := > > copy $c := > > <entry> > > <title>entry title</title> > > <content>entry content</content> > > </entry> > > modify ( > > return replace value of node $c/title with 'new entry title', > > return replace value of node $c/content with 'new entry content' > > ) > > return $c > > return replace node doc('doc1')/entry with $node > > Note: doc1 is a document in the database with 'entry' as the root > element. > > - Sony > > On Tue, Apr 26, 2011 at 10:40 AM, Christian Grün < > christian.gruen at gmail.com> > > wrote: > >> > >> Sony, > >> > >> please provide complete queries, otherwise it's difficult to give > >> constructive feedback (e.g.: $entry isn't specified anywhere, etc). > >> > >> Christian > >> > >> > >> On Tue, Apr 26, 2011 at 3:59 PM, Sony Vijay <sony.vibh at gmail.com> > wrote: > >> > Hi, > >> > I am wondering if there is a way to convert a String into a Node > within > >> > XQuery. > >> > For example, consider the xquery > >> > let $node := > >> > copy $c := > >> > <entry> > >> > <title>entry title</title> > >> > <content>entry content</content> > >> > </entry> > >> > modify ( > >> > return replace value of node $entry/title with 'new entry title', > >> > return replace value of node $entry/content with 'new entry > content' > >> > ) > >> > return $c > >> > > >> > return replace node doc('doc1')/entry with $c > >> > The above xquery throws the error: [XPTY0019] Context node required > for > >> > entry; xs:string found. How do I fix this ? > >> > Thanks, > >> > Sony > >> > > >> > _______________________________________________ > >> > BaseX-Talk mailing list > >> > BaseX-Talk at mailman.uni-konstanz.de > >> > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > >> > > >> > > > > > >
SV
Sony Vijay26 Apr 2011 19:26 #
... I used multiple statements in the modify function based on the documentation: http://docs.basex.org/wiki/Update
Quoted text · Sony Vijay · 90 lines
On Tue, Apr 26, 2011 at 11:23 AM, Sony Vijay <sony.vibh at gmail.com> wrote: > Yes, I tried the query without the return earlier. I saw a syntax > error: [XPST0003] Expecting 'where', 'order' or 'return' expression. > > I return $c in my query but I still see the error. Looking at the error, I > guessed that when a transform function is used in a query, return is > required to replace. > > Also, I am using two return statements inside the modify function. I am not > sure if that is allowed. In any event, is there a way to update multiple > nodes at the same time with or without using modify. > > Thanks, > Sony > > On Tue, Apr 26, 2011 at 11:02 AM, Christian Grün < > christian.gruen at gmail.com> wrote: > >> …still incorrect; "return" before "replace" doesn't make sense. >> C. >> >> >> On Tue, Apr 26, 2011 at 4:58 PM, Sony Vijay <sony.vibh at gmail.com> wrote: >> > Hi Christian, >> > The complete query is: >> > let $node := >> > copy $c := >> > <entry> >> > <title>entry title</title> >> > <content>entry content</content> >> > </entry> >> > modify ( >> > return replace value of node $c/title with 'new entry title', >> > return replace value of node $c/content with 'new entry content' >> > ) >> > return $c >> > return replace node doc('doc1')/entry with $node >> > Note: doc1 is a document in the database with 'entry' as the root >> element. >> > - Sony >> > On Tue, Apr 26, 2011 at 10:40 AM, Christian Grün < >> christian.gruen at gmail.com> >> > wrote: >> >> >> >> Sony, >> >> >> >> please provide complete queries, otherwise it's difficult to give >> >> constructive feedback (e.g.: $entry isn't specified anywhere, etc). >> >> >> >> Christian >> >> >> >> >> >> On Tue, Apr 26, 2011 at 3:59 PM, Sony Vijay <sony.vibh at gmail.com> >> wrote: >> >> > Hi, >> >> > I am wondering if there is a way to convert a String into a Node >> within >> >> > XQuery. >> >> > For example, consider the xquery >> >> > let $node := >> >> > copy $c := >> >> > <entry> >> >> > <title>entry title</title> >> >> > <content>entry content</content> >> >> > </entry> >> >> > modify ( >> >> > return replace value of node $entry/title with 'new entry title', >> >> > return replace value of node $entry/content with 'new entry >> content' >> >> > ) >> >> > return $c >> >> > >> >> > return replace node doc('doc1')/entry with $c >> >> > The above xquery throws the error: [XPTY0019] Context node required >> for >> >> > entry; xs:string found. How do I fix this ? >> >> > Thanks, >> >> > Sony >> >> > >> >> > _______________________________________________ >> >> > BaseX-Talk mailing list >> >> > BaseX-Talk at mailman.uni-konstanz.de >> >> > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> >> > >> >> > >> > >> > >> > >
SV
Sony Vijay26 Apr 2011 20:38 #
Edited the xpath in the query. The final xquery looks like so:
let $node :=
copy $c :=
<entry>
<title>entry title</title>
<content>entry content</content>
</entry>
modify (
return replace value of node $c//title with 'new entry title',
return replace value of node $c//content with 'new entry content'
)
return $c
replace node doc('doc1')/entry with $nodeThis does not work.
Quoted text · Sony Vijay · 97 lines
On Tue, Apr 26, 2011 at 11:26 AM, Sony Vijay <sony.vibh at gmail.com> wrote: > ... I used multiple statements in the modify function based on the > documentation: http://docs.basex.org/wiki/Update > > > On Tue, Apr 26, 2011 at 11:23 AM, Sony Vijay <sony.vibh at gmail.com> wrote: > >> Yes, I tried the query without the return earlier. I saw a syntax >> error: [XPST0003] Expecting 'where', 'order' or 'return' expression. >> >> I return $c in my query but I still see the error. Looking at the error, I >> guessed that when a transform function is used in a query, return is >> required to replace. >> >> Also, I am using two return statements inside the modify function. I am >> not sure if that is allowed. In any event, is there a way to update multiple >> nodes at the same time with or without using modify. >> >> Thanks, >> Sony >> >> On Tue, Apr 26, 2011 at 11:02 AM, Christian Grün < >> christian.gruen at gmail.com> wrote: >> >>> …still incorrect; "return" before "replace" doesn't make sense. >>> C. >>> >>> >>> On Tue, Apr 26, 2011 at 4:58 PM, Sony Vijay <sony.vibh at gmail.com> wrote: >>> > Hi Christian, >>> > The complete query is: >>> > let $node := >>> > copy $c := >>> > <entry> >>> > <title>entry title</title> >>> > <content>entry content</content> >>> > </entry> >>> > modify ( >>> > return replace value of node $c/title with 'new entry title', >>> > return replace value of node $c/content with 'new entry content' >>> > ) >>> > return $c >>> > return replace node doc('doc1')/entry with $node >>> > Note: doc1 is a document in the database with 'entry' as the root >>> element. >>> > - Sony >>> > On Tue, Apr 26, 2011 at 10:40 AM, Christian Grün < >>> christian.gruen at gmail.com> >>> > wrote: >>> >> >>> >> Sony, >>> >> >>> >> please provide complete queries, otherwise it's difficult to give >>> >> constructive feedback (e.g.: $entry isn't specified anywhere, etc). >>> >> >>> >> Christian >>> >> >>> >> >>> >> On Tue, Apr 26, 2011 at 3:59 PM, Sony Vijay <sony.vibh at gmail.com> >>> wrote: >>> >> > Hi, >>> >> > I am wondering if there is a way to convert a String into a Node >>> within >>> >> > XQuery. >>> >> > For example, consider the xquery >>> >> > let $node := >>> >> > copy $c := >>> >> > <entry> >>> >> > <title>entry title</title> >>> >> > <content>entry content</content> >>> >> > </entry> >>> >> > modify ( >>> >> > return replace value of node $entry/title with 'new entry title', >>> >> > return replace value of node $entry/content with 'new entry >>> content' >>> >> > ) >>> >> > return $c >>> >> > >>> >> > return replace node doc('doc1')/entry with $c >>> >> > The above xquery throws the error: [XPTY0019] Context node required >>> for >>> >> > entry; xs:string found. How do I fix this ? >>> >> > Thanks, >>> >> > Sony >>> >> > >>> >> > _______________________________________________ >>> >> > BaseX-Talk mailing list >>> >> > BaseX-Talk at mailman.uni-konstanz.de >>> >> > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >>> >> > >>> >> > >>> > >>> > >>> >> >> >
SV
Thanks. I realized the syntax error a couple of minutes ago. I was trying out a more complex example meanwhile.
2011/4/26 Leo Wörteler <lw at basex.org>
Quoted text · Leo Wörteler · 33 lines
> Hi Sony, > > Am 26.04.2011 18:38, schrieb Sony Vijay: > > let $node := > > copy $c := > > <entry> > > <title>entry title</title> > > <content>entry content</content> > > </entry> > > modify ( > > return replace value of node $c//title with 'new entry title', > > return replace value of node $c//content with 'new entry content' > > ) > > return $c > > replace node doc('doc1')/entry with $node > > Please check beforehand that your queries don't contain obvious syntax > errors like the one above. This can be easily accomplished by > copy-pasting them into the BaseX GUI [1], which highlights errors quite > nicely. > > > This does not work. > > Try deleting both 'return' keywords in the 'modify' clause and adding > one at the beginning of the last line. > And please keep in mind that this mailing list should be primarily about > BaseX, not XQuery syntax. > > HTH, > Leo > __________ > [1] http://basex.org/products/download/all-downloads/ >
Written for BaseX 6.6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery