Hello Florent,
first of all, it doesn't matter here whether you use XQuery in a web context or not - It would throw the same error even without using RESTXQ.
The problem with your first error was that you selected multiple attributes and constructed and element with this - As an XML element can not have multiple attributes with the same name, this will not work. Thats why it does work with elements, because each element can have multiple child elements with the same name. In your proposed solution, string() converts the attributes to plain strings, and of course your element can hav a text child.
So your solution is very much ok, but "what the best way" is enterily depends on what you want as output. If the current solution gives you your desired ouput, then I see no harm in using this one. However, if it is not and you want more help, it would be nice if you could provide a small example output on what you want to get back as result.
Cheers Dirk On 05/07/2015 03:38 AM, Florent Gallaire wrote:
I answer to myself : db:open('factbook')//city/@name/string() will works fine.
Still, is there a best way ? Is there some problems with that ? Is the element way better for xquery web usage ?
Cheers
Florent
On Thu, May 7, 2015 at 2:18 AM, Florent Gallaire fgallaire@gmail.com wrote:
In the RESTXQ documentation there is this example which works fine :
declare %rest:path("cities") %output:method("json") %output:json("format=jsonml") function page:cities() { element cities { db:open('factbook')//city/name } };
If I have the same factbook db but with name as attribute and not as element, with the only change in the code the xquery request db:open('factbook')//city/@name I will have the error message: [XQDY0025] Duplicate attribute 'name'.
That's ok, but what is the right way in xquery to easily use multiple attributes as return value of request.
Is the right way to prefer elements to attributes ?
Cheers
Florent
-- FLOSS Engineer & Lawyer