do not interpret text nodes as embedded expressions (Expecting '}' but found...)

Friday, 18 October 2013 · 5 messages · last reply 23 Oct 2013
EK
Erdal Karaca18 Oct 2013 15:05 #
Hi all, How can I process this query in basex:
let $x := doc(<a>main(){int i = 0;}</a>)
return replace value of node $x with ""
There are text contents that contain, for example, c code with curly braces which I do not want to be interpreted as embeded expressions. As a workaround I could escape the curly braces, But, is there a better way/option to suppress interpreting text contents that look like embedded expressions? Thanks!
ML
Marco Lettere18 Oct 2013 15:12 #
Maybe with a CDATA section?
let $x := doc(<a><![CDATA[main(){int i = 0;}]]></a>)
return replace value of node $x with ""
M.
Quoted text · Erdal Karaca · 23 lines
On 10/18/2013 03:05 PM, Erdal Karaca wrote: > Hi all, > How can I process this query in basex: > > let $x := doc(<a>main(){int i = 0;}</a>) > return replace value of node $x with "" > > > There are text contents that contain, for example, c code with curly > braces which I do not want to be interpreted as embeded expressions. > > As a workaround I could escape the curly braces, But, is there a > better way/option to suppress interpreting text contents that look > like embedded expressions? > > Thanks! > > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
EK
Erdal Karacain reply to Wendell Piez, 18 Oct 2013, 17:3118 Oct 2013 15:56 #
Sorry, all, here is a more specific question: The query is constructed at runtime and executed using the QueryProcessor command. Query: replace node . with <a>main(){int i=0;}</a> Execution error: Expecting '}' found ... If I try to bind the replacement as a global parameter, the error message is: Single element, text, attribute, comment or pi expected as replace target. The java code:
QueryProcessor query = new QueryProcessor("replace node . with $replacement",
context);
query.bind("replacement", "<a>main(){int i=0;}</a>");
The problem with escpaing the curly braces (or wrapping all text content nodes and maybe attribute values, too) is the extra overhead which would decrease performance. 2013/10/18 Wendell Piez <wapiez at wendellpiez.com>
Quoted text · Wendell Piez · 47 lines
> Erdal, > > Escaping the curly braces by doubling them would be the "normal" way. > You ask for a better way; can you be more specific as to what needs to > be improved? Would this be an improvement? > > let $expr := 'main(){int i=0;}' > let $x := doc(<a>{ $expr }</a>) > return ... > > Cheers, Wendell > Wendell Piez | http://www.wendellpiez.com > XML | XSLT | electronic publishing > Eat Your Vegetables > _____oo_________o_o___ooooo____ooooooo_^ > > > On Fri, Oct 18, 2013 at 9:05 AM, Erdal Karaca <erdal.karaca.de at gmail.com> > wrote: > > Hi all, > > How can I process this query in basex: > > > > let $x := doc(<a>main(){int i = 0;}</a>) > > return replace value of node $x with "" > > > > > > There are text contents that contain, for example, c code with curly > braces > > which I do not want to be interpreted as embeded expressions. > > > > As a workaround I could escape the curly braces, But, is there a better > > way/option to suppress interpreting text contents that look like embedded > > expressions? > > > > Thanks! > > > > > > _______________________________________________ > > BaseX-Talk mailing list > > BaseX-Talk at mailman.uni-konstanz.de > > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
WP
Wendell Piezin reply to Erdal Karaca, 18 Oct 2013, 15:0518 Oct 2013 17:31 #
Erdal, Escaping the curly braces by doubling them would be the "normal" way. You ask for a better way; can you be more specific as to what needs to be improved? Would this be an improvement?
let $expr := 'main(){int i=0;}'
let $x := doc(<a>{ $expr }</a>)
return ...
Cheers, Wendell Wendell Piez | http://www.wendellpiez.com XML | XSLT | electronic publishing Eat Your Vegetables _____oo_________o_o___ooooo____ooooooo_^
Quoted text · Erdal Karaca · 23 lines
On Fri, Oct 18, 2013 at 9:05 AM, Erdal Karaca <erdal.karaca.de at gmail.com> wrote: > Hi all, > How can I process this query in basex: > > let $x := doc(<a>main(){int i = 0;}</a>) > return replace value of node $x with "" > > > There are text contents that contain, for example, c code with curly braces > which I do not want to be interpreted as embeded expressions. > > As a workaround I could escape the curly braces, But, is there a better > way/option to suppress interpreting text contents that look like embedded > expressions? > > Thanks! > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
EK
Erdal Karacain reply to Erdal Karaca, 18 Oct 2013, 15:5623 Oct 2013 21:11 #
FYI: solved using parse-xml():
QueryProcessor query = new QueryProcessor("replace node . with
parse-xml($replacement)", context);
query.bind("replacement", "<a>main(){int i=0;}</a>");
2013/10/18 Erdal Karaca <erdal.karaca.de at gmail.com>
Quoted text · Erdal Karaca · 76 lines
> Sorry, all, here is a more specific question: > > The query is constructed at runtime and executed using the QueryProcessor > command. > > Query: replace node . with <a>main(){int i=0;}</a> > Execution error: Expecting '}' found ... > > If I try to bind the replacement as a global parameter, the error message > is: Single element, text, attribute, comment or pi expected as replace > target. > > The java code: > > QueryProcessor query = new QueryProcessor("replace node . with > $replacement", context); > query.bind("replacement", "<a>main(){int i=0;}</a>"); > > The problem with escpaing the curly braces (or wrapping all text content > nodes and maybe attribute values, too) is the extra overhead which would > decrease performance. > > > > 2013/10/18 Wendell Piez <wapiez at wendellpiez.com> > >> Erdal, >> >> Escaping the curly braces by doubling them would be the "normal" way. >> You ask for a better way; can you be more specific as to what needs to >> be improved? Would this be an improvement? >> >> let $expr := 'main(){int i=0;}' >> let $x := doc(<a>{ $expr }</a>) >> return ... >> >> Cheers, Wendell >> Wendell Piez | http://www.wendellpiez.com >> XML | XSLT | electronic publishing >> Eat Your Vegetables >> _____oo_________o_o___ooooo____ooooooo_^ >> >> >> On Fri, Oct 18, 2013 at 9:05 AM, Erdal Karaca <erdal.karaca.de at gmail.com> >> wrote: >> > Hi all, >> > How can I process this query in basex: >> > >> > let $x := doc(<a>main(){int i = 0;}</a>) >> > return replace value of node $x with "" >> > >> > >> > There are text contents that contain, for example, c code with curly >> braces >> > which I do not want to be interpreted as embeded expressions. >> > >> > As a workaround I could escape the curly braces, But, is there a better >> > way/option to suppress interpreting text contents that look like >> embedded >> > expressions? >> > >> > Thanks! >> > >> > >> > _______________________________________________ >> > BaseX-Talk mailing list >> > BaseX-Talk at mailman.uni-konstanz.de >> > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> > >> _______________________________________________ >> BaseX-Talk mailing list >> BaseX-Talk at mailman.uni-konstanz.de >> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> > >

⚡Generated with XQuery