dbTalk Databases Forums  

python example for dbxml

comp.databases.berkeley-db comp.databases.berkeley-db


Discuss python example for dbxml in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
jefm
 
Posts: n/a

Default 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


Reply With Quote
  #2  
Old   
jefm
 
Posts: n/a

Default Re: python example for dbxml - 02-08-2006 , 08:31 PM






Hi,
I was a little bit too fast in posting this cry for help - found the
problem:
the following snippet fixes it:
####begin codesnippet####
while res.hasNext():
value = res.next()
print value
####end codesnippet####

while I am reading through the Java Tutorial and trying to adapt the
examples to Python, I notice that the python dbxml module is missing
some pieces:
- there is no XmlException
- there is no function set_error_stream (used in example 2.3)

any comments on this ?


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.