0

我在 python 中完成了以下代码,以获取存储在 eXist-db 中的 XML 中的查询响应。我得到了值,但问题是下面的输出中给出的“即时”类型。这是我的代码:

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)

现在查询工作正常,结果也打印为:

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

我想要的是返回列表“结果”中附加的值。我尝试了类型转换但失败了。我如何实现这一目标?

4

1 回答 1

2

这很奇怪 -文档似乎说该db.retrieve函数应该返回一个字符串,但显然它没有。在任何情况下,由于 print 语句从中获取了有用的字符串,因此其中一个应该可以工作:

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

或者

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

只需取消注释该#result = list()行,并将上述之一添加到 for 循环中。

于 2013-08-14T12:58:15.297 回答