سؤال

I have done following code in python to get the response of query in XML stored in eXist-db. I get the value but the problem is type 'instant' as given in the output below. Here's my code:

from eulexistdb import db
class TestExist:
    def __init__(self):
        self.db = db.ExistDB("http://localhost:8899/exist/")   

    def get_res(self,query):
        #result = list()
        res = self.db.executeQuery(query)
        hits = self.db.getHits(res)        
        for i in range(hits):
            print self.db.retrieve(res,i)
            print type(self.db.retrieve(res,i))
xquery = '''
let $x:= doc("/db/sample/books.xml")
return $x/bookstore/book/price/text()'''
a = TestExist()
a.get_res(xquery)

Now the query works fine and result too get printed as:

30.00
<type 'instance'>
29.99
<type 'instance'>
49.99
<type 'instance'>
39.95
<type 'instance'>

What I want is to return the value appended in list 'result'. I tried type conversion but failed. How do I achieve this?

هل كانت مفيدة؟

المحلول

That's strange - the docs seem to say that the db.retrieve function should return a string, but apparently it does not. In any case, since the print statement gets a useful string out of it, one of these should work:

result.append(str(self.db.retrieve(res,i)))

or

result.append(repr(self.db.retrieve(res,i)))

Just uncomment the #result = list() line, and add one of the above into the for loop.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top