python example for dbxml -
02-08-2006
, 07:03 PM
Hi,
newbie question
Does anyone know of example Python code for interfacing dbxml ?
I tried to convert the C++ example in "Chapter 2. XQuery and Berkeley
DB XML" of "The Berkeley DB XML API" to Python.
It seems to work until the while-part blows up:
#### begin snippet####
import dbxml
mgr = dbxml.XmlManager()
# Create the phonebook container
cont = mgr.createContainer("phone4.dbxml")
# Add the phonebook entries to the container
uc = mgr.createUpdateContext() # XmlUpdateContext
cont.putDocument("phone1",
'''
<phonebook>
<name>
<first>Tom</first>
<last>Jones</last>
</name>
<phone type=\"home\">420-203-2032</phone>
</phonebook>
''', uc)
cont.putDocument("phone2",
'''
<phonebook>
<name>
<first>Lisa</first>
<last>Smith</last>
</name>
<phone type=\"home\">420-992-4801</phone>
<phone type=\"cell\">390-812-4292</phone>
</phonebook>
''', uc);
# Run an XQuery against the phonebook container
qc = mgr.createQueryContext() # XmlQueryContext
res = mgr.query("collection('phone4.dbxml')/phonebook[name/first =
'Lisa']/phone[@type = 'home']/text()", qc);
# XmlResults
# Print out the result of the query
value = dbxml.XmlValue()
while value != None:
value = res.next()
print str(value)
#####end snippet####
I get the following error message:
C:\temp\test>testdbxml.py
<dbxml.XmlValuePtr; proxy of C++ XmlValue instance at
_d0fcf200_p_XmlValue>
Traceback (most recent call last):
File "C:\temp\test\testdbxml.py", line 42, in ?
value = res.next()
File "C:\Python24\Lib\site-packages\dbxml.py", line 415, in next
def next(*args): return _dbxml.XmlResults_next(*args)
StopIteration: End of results.
anybody any idea of how to use this particualr example and/or general
guidelines on interfacing to dbxml in Python ?
thx
Jef |