Hi Kristian,
the client bindings are all fairly simple and generic. However, the BaseX server protocol provides the command "FULL", which will also give you the XQuery data type of each item [1]. You could enhance the Python client to retrieve the types as well.
Hope this helps Christian
[1] http://docs.basex.org/wiki/Server_Protocol
Am Do., 1. Nov. 2018 13:01 hat Kristian Kankainen kristian@keeleleek.ee geschrieben:
Hello,
XQuery is a lovely language and together with BaseX it is very lovely.
But now, for a project that need Python, I find difficulties understanding the general workflow communicating between BaseX and Python.
My basic situation boils down to 1) execute a query on BaseX that returns a list of data 2) analyse every item in the in Python 3) push the analysis result back in to BaseX.
I have done updates like this solely in XQuery but this time I need the analysis part done in Python.
Since I seem to only get a list of strings out of a query executed by the client, is this usecase even possible?
Below is attached my sample running code
Best regards, Kristian K
from BaseXClient import BaseXClient # open a session session = BaseXClient.Session('localhost', 1984, 'admin', 'admin') # execute a query that returns a list of entry elements query = session.query(""" let $list := <list> <entry> <a>1</a> <b>2</b> </entry> <entry> <a>1</a> <b>2</b> <c>3</c> </entry> </list> let $items := for $entry in $list/entry[not(exists(./c))] return $entry return $items """ ) # process each item of the query for typecode, item in query.iter(): print(type(item)) print(item) session.close()
This returns simply: <class 'str'> # the type of returned item is of class 'str' <entry> # this is the content of the plain text object <a>1</a> <b>2</b>
</entry>