Hi,
when I use the client/server interface and run a query that returns multiple nodes, BaseX appears to return the results concatenated (and, somewhat oddly, with interspersed newlines).
For instance,
xquery declare namespace atom='http://www.w3.org/2005/Atom'; doc('myfeed')//atom:title
returns:
<title xmlns="http://www.w3.org/2005/Atom">First Title</title> <title xmlns="http://www.w3.org/2005/Atom">Second Title</title> <title xmlns="http://www.w3.org/2005/Atom">Third Title</title> ....
Does anybody happen to know how to parse those into separate XML documents in Java? (Short of preprocessing the XML to find the matching end tag for each element?) For background, classes such as javax.xml.parsers.DocumentBuilder can only parse one document at a time, and throw an error if the input source contains multiple documents/fragments.
Alternatively, would it make sense for BaseX to support returning results one by one (perhaps using a cursor approach) to ease the client's task of parsing the returned XML?
- Godmar
Hi Godmar,
to use iteration as in [1] with
while(query.more()) { System.out.print(query.next()); }
could help your issue. As I am not sure about the XPath semantics this could involve rewriting your Expression to a for/let loop to really get results one at a time.
Hope this helps, feel free to ask more.
Kind regards Michael
[1] https://svn.uni-konstanz.de/dbis/basex/trunk/api/etc/java/QueryExample.java
Am 19.08.2010 um 06:39 schrieb Godmar Back:
Hi,
when I use the client/server interface and run a query that returns multiple nodes, BaseX appears to return the results concatenated (and, somewhat oddly, with interspersed newlines).
For instance,
xquery declare namespace atom='http://www.w3.org/2005/Atom'; doc('myfeed')//atom:title
returns:
<title xmlns="http://www.w3.org/2005/Atom">First Title</title> <title xmlns="http://www.w3.org/2005/Atom">Second Title</title> <title xmlns="http://www.w3.org/2005/Atom">Third Title</title> ....
Does anybody happen to know how to parse those into separate XML documents in Java? (Short of preprocessing the XML to find the matching end tag for each element?) For background, classes such as javax.xml.parsers.DocumentBuilder can only parse one document at a time, and throw an error if the input source contains multiple documents/fragments.
Alternatively, would it make sense for BaseX to support returning results one by one (perhaps using a cursor approach) to ease the client's task of parsing the returned XML?
On Thu, Aug 19, 2010 at 4:06 AM, Michael Seiferle < michael.seiferle@uni-konstanz.de> wrote:
[1] https://svn.uni-konstanz.de/dbis/basex/trunk/api/etc/java/QueryExample.java
I see. So you did implement a hidden cursor protocol with 0, 1, 2, and 3s sent to the server.
(Actually, I'm just noticing it's document in https://svn.uni-konstanz.de/dbis/basex/trunk/api/etc/readme.txt )
Thanks!
- Godmar
Hi Godmar,
So you did implement a hidden cursor protocol with 0, 1, 2, and 3s sent to the server.
the client sends the query with an starting control-code (0) to the server. The server knows now that the query has to execute in an iterative manner and stores this query with the corresponding id in a list. The client gets an id for this query back. So if the client wants results of this query it sends the control-code (1) and the id to the server. So the server knows that the next result has to send to the client.
The control-code (3) is needed for the creation of a database (see the create-method).
I hope this explains a bit, kind regards, Andreas
Godmar Back schrieb:
On Thu, Aug 19, 2010 at 4:06 AM, Michael Seiferle <michael.seiferle@uni-konstanz.de mailto:michael.seiferle@uni-konstanz.de> wrote:
[1] https://svn.uni-konstanz.de/dbis/basex/trunk/api/etc/java/QueryExample.java
I see. So you did implement a hidden cursor protocol with 0, 1, 2, and 3s sent to the server.
(Actually, I'm just noticing it's document in https://svn.uni-konstanz.de/dbis/basex/trunk/api/etc/readme.txt )
Thanks!
- Godmar
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
basex-talk@mailman.uni-konstanz.de