0

eXist-db に格納されている XML でクエリの応答を取得するために、Python で次のコードを実行しました。私は値を取得しますが、問題は以下の出力に示されているように「インスタント」タイプです。これが私のコードです:

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 に答える