how to serialize XQuery results?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

how to serialize XQuery results?

Denis Sukhoroslov
Hi,

I have a client-server application. Server performs XQuery and return results to client. How can I serialize XQuery results properly? So far I serialize it to String as:

    QueryResult.serialize(((NodeOverNodeInfo) item).getUnderlyingNodeInfo());

but some of the query results are not Documents, and the serialization throws exception:

    Cannot serialize a free-standing attribute node (a)

on the query like this:

    "<e/>, <e a=''/>/@*"

Is it possible to serialize XQuery results without the standard strict validation? Or, any kind of binary serialization which will allow me to build the same xquery results sequence on the client side?

Thanks, Denis.

------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: how to serialize XQuery results?

Michael Kay
I've raised the same issue recently at W3C:


You might like to contribute to that discussion by explaining your use case.

There isn't currently a serialization method that can serialize any possible XDM value, especially when it comes to the new data types such as maps and arrays.

There's also a question over how much information you want the serialization to capture. For example:

* with nodes, do you need to know the type annotations?

* with atomic values, do you need to distinguish the xs:string 2015-01-01 from the xs:date 2015-01-01?

* if your query returns two nodes that both serailize as <x/>, do you need to know whether these are actually the same node?

For a long time Saxon has offered the -wrap option on the XQuery command line which creates an XML serialization of the results that captures some of this, and which also allows serialization of, for example, free-standing attribute nodes. In the API this is achieved by calling QueryResult.wrap() and then putting the resulting document node through normal XML serialization. The wrap format is fairly obvious to deduce by inspection but it's not well documented, and I don't think Saxon includes any tool to reconstruct the XDM value from this representation.


Michael Kay
Saxonica
+44 (0) 118 946 5893




On 31 Dec 2014, at 11:19, Denis Sukhoroslov <[hidden email]> wrote:

Hi,

I have a client-server application. Server performs XQuery and return results to client. How can I serialize XQuery results properly? So far I serialize it to String as:

    QueryResult.serialize(((NodeOverNodeInfo) item).getUnderlyingNodeInfo());

but some of the query results are not Documents, and the serialization throws exception:

    Cannot serialize a free-standing attribute node (a)

on the query like this:

    "<e/>, <e a=''/>/@*"

Is it possible to serialize XQuery results without the standard strict validation? Or, any kind of binary serialization which will allow me to build the same xquery results sequence on the client side?

Thanks, Denis.
------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: how to serialize XQuery results?

G. Ken Holman
In reply to this post by Denis Sukhoroslov
I know Michael as already addressed this, but if
you have to get something going in the short
term, I have a "brute force" way to approach your issue.

At 2014-12-31 14:19 +0300, Denis Sukhoroslov wrote:
>I have a client-server application. Server
>performs XQuery and return results to client.
>How can I serialize XQuery results properly?

By ensuring that the result is an XML document or
external general entity.  You can create an
external parsed general entities to be referenced
by entity references in other documents.

>So far I serialize it to String as:
>
>Â  Â  QueryResult.serialize(((NodeOverNodeInfo)
>item).getUnderlyingNodeInfo());
>
>but some of the query results are not Documents,
>and the serialization throws exception:
>
>Â  Â  Cannot serialize a free-standing attribute node (a)
>
>on the query like this:
>
>Â  Â Â "<e/>, <e a=''/>/@*"
>
>Is it possible to serialize XQuery results
>without the standard strict validation?

I don't think so.

>Or, any kind of binary serialization which will
>allow me to build the same xquery results sequence on the client side?

No .... but ....

What if you, in your server, simply always wrap
your result in a document element named <result>
and in your client always disregard the document element named <result>.

Then, if your query result is an attribute, it
gets attached to the result document element.

If your query result is a document, it becomes
the single child of the result document element.

If your query result is an external general
entity, you even get the benefit of the result
document element changing the external general
entity into a complete XML document.  This means
you don't have to use an entity reference in
another document in order to get access to the
content.  Any XML process would have access to
your query result without the need to accommodate
that an external parsed general entity, in and of
itself, cannot be inspected without special handling.

Your new rule of thumb is simply to ignore the
query result document element and the rest of the
XDM tree is your actual query result.

I hope this is considered helpful.

.. . . . . . . Ken

--
Check our site for free XML, XSLT, XSL-FO and UBL developer resources |
Free 5-hour lecture:  http://www.CraneSoftwrights.com/links/video.htm |
Crane Softwrights Ltd.             http://www.CraneSoftwrights.com/z/ |
G. Ken Holman                    mailto:[hidden email] |
Google+ profile:       http://plus.google.com/+GKenHolman-Crane/about |
Legal business disclaimers:     http://www.CraneSoftwrights.com/legal |


---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com


------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help