I should have run your query before sending you an answer. The
following query should work:
json:serialize(
<json type="array" objects='_'>{
for $user in
collection("saveresult")//user[_id="1f2cda8f-a18a-44ba-8d17-73626d472306"]
return
<_>
<testId>{$user/test/_id}</testId>
<grade>{$user/user_info/user_grade}</grade>
</_>
}</json>
)
>
>> Which is what I expected after reading about the JSONML format. (Not too
>> happy with that format, but that's another story).
>
> I agree; JSONML is a quasi-standard we have adopted, which is mainly useful
> for converting arbitrary XML to JSON. If you can decide how your XML format
> looks like, I would recommend the standard conversion format:
>
> declare option output:method "json";
>
> <json type="array" objects='_'>{
> for $user in
> collection("saveresult")//user[_id="1f2cda8f-a18a-44ba-8d17-73626d472306"]
> return
> <testResults>
> <testId>{$user/test/_id}</testId>
> <grade>{$user/user_info/user_grade}</grade>
> </testResults>
> }</json>
>
>>
> Running exactly the same XQuery form within a PHP script however yields
>> this:
>
> The query results are currently sent to all clients in their standard format
> (i.e., ignoring all serialization parameters). That's why you'll need to
> convert your JSON within XQuery:
>
> json:serialize(
> <json type="array" objects='_'>{
> ...
> }</json>
> )
>
> If I remember what was the reason for that design decision, I'll give you an
> update soon..
>
> Hope this helps,
> Christian
>
>