QIODevice and QXmlQuery

December 11, 2007

I have not yet seen an API for XQuery in which integrating the data model, atomic values, nodes and all, into the interfacing language has been a walk in the park.

At the top of the list of things people tend to ask on the forums around is “How do I get XML represented as a sequence of bytes in Java/C++ into my query?”, whose result is clear — a tree fragment for the query to operate on — but whose method for reaching is not that given if you ask me.

There is no “bytestream” type in XQuery. Should the user build the tree herself and then pass the tree to the query? Should the implementation in some voodoish way be instructed how to treat a string or custom type? Shouldn’t the query engine do it such that its scope of analysis is increased and its done the way it prefers it?

What I sense have been the problem with some solutions is that they mix the data, the bytestream, with interpretation.

In Qt this manifestate itself with that the content of a QIODevice should appear in a QXmlQuery. The way it’s now provided, is that when a QIODevice is bound to a variable using QXmlQuery::bindVariable(), the query sees a URI(an instance of xs:anyURI) which behind the scenes maps to the QIODevice the user bound. Hence, if the purpose is to build an XML document, one passes the URI to the builtin fn:doc() function.

I hope this is clean. Since it’s handled like any other URI, custom extensions stays at a minimum, error reporting is consistent, and the interpretation hasn’t been coupled with the data. For instance, later on I hope to merge in support for XInclude and XQuery Update, and in those cases the URI is again simply passed to for instance fn:put().

One can weight quite well on URIs and the abstraction the XPath Data Model provides, it seems.

5 Responses to “QIODevice and QXmlQuery”

  1. Berzeck Says:

    Hi, i am trying to develop a client – server application, the server connects to the database and the clients connect to the server, my problem is how do i serialize database querys ( including blobs ) and pass them via network from the server to the client ?

    Can i use XQuery to implement a solution ?

    PD: Sorry my bad english
    thank you

  2. englich Says:

    It’s a bit hard to tell. Maybe your client/server layer is a bit too low level for XQuery to help out. However, if the server is exposed as files(either physically or “virtually” using a web server/service), XQuery can be of use.

    Another alternative is that you sub-class QSimpleXmlNodeModel and let that one interface your server, and then queries operate on your QSimpleXmlNodeModel.

  3. Nicer Says:

    good job

  4. Markus Says:

    Hey, are you still planning for XInclude support in xmlpatterns? I really love the possibilitys of QtXmlPatterns :-)

  5. englich Says:

    Hi Markus,

    Yeah, XInclude is a nifty little thing that surely would technically make sense to support. However, right now we don’t have any plans of implementing it, due to it making more sense to prioritize other things.


Leave a Reply