[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

Programmatically constructing sequences ("a", "b", "c") for XQuery

Michael Ludwig mlu at as-guides.com
Mon Aug 10 19:42:20 PDT 2009


  Programmatically constructing sequences ("a"
Michael Ludwig schrieb:

> I think I know what the problem is. The XmlValue constructor does not
> seem designed to accept sequences. What I mean to be a sequence -
> ('eins','zwei','drei') - is interpreted as a literal string.
>
> So I think a (somewhat kludgy) solution would be to construct a mini
> document from the input parameters, store it in the database and then
> join against that:
>
> <Params>
>    <F>eins</F>
>    <F>zwei</F>
>    <F>drei</F>
> </Params>
>
> Or, preferably, use an XmlResolver. Much better than storing
> parameters in the database, if only temporarily.

For the record, these clumsy solutions aren't needed. Instead, as Andrew
Welch pointed out, the solution is to not abuse the XmlValue interface,
to simply pass in the string as a string with a suitable delimiter (like
"eins,zwei,drei") and construct the sequence of strings at the XQuery
level using the tokenize() function.

   String query =
    "declare variable $files as xs:string+ := tokenize($param, ','); " +
    "for $d in collection('ab')[//File = $files] order by $d/@ts return $d";

   ...

   xqc.setVariableValue("param", new XmlValue("eins,zwei,drei"));

(Or construct the XmlValue dynamically.)

-- 
Michael Ludwig


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.