XQuery library under Python [closed]
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Im开发者_如何学Pythonprove this questionIs there any existing way to run XQuery under python? (not starting to build a parser yourself in other words).
I got a ton of legacy XQuery that I want to port to our new system, or rather I want to port the framework and not XQuery.
Therefore: Is there any library that allows me to run XQuery under python?
Sort of ...
Looking through the W3C implementations list for XQuery there is:
- Python bindings for Zorba
- Sedna is a free native XML database with API for Python.
A few Python examples with Zorba, from here
import sys
import zorba_api
def example1(zorba):
xquery = zorba.compileQuery("1+2")
print xquery.printPlanAsXML()
print xquery.execute()
return
def example2(zorba):
xquery = zorba.compileQuery("(1,2,3,4,5)")
iter = xquery.iterator()
iter.open()
item = zorba_api.Item_createEmptyItem()
while iter.next(item):
print item.getStringValue()
iter.close()
iter.destroy()
return
def example3(zorba):
try:
xquery = zorba.compileQuery("1 div 0")
print xquery.execute()
except RuntimeError, e:
print e
return
There may be C implementation in that list which can easily be bound to Python. Hope this helps, I was somewhat surprised to see so few implementations. Although, XQuery isn't the most desired of the XML tools I suppose.
You could use Jython to run the Python code -- that gives you access to some of the XQuery processors from the Java world. For example Saxon.
Zorba 1.2 works from python. After installation you will get a python folder under zorba folder. Append it to sys.path, with zorba\bin folder also. After all manipulations import "zorba_api" will work!
I had problems like Ted and tried to use answer from vadim. However, I had still problems to load zorba_api properly, complaining "ImportError DLL load failed" (not telling which one, using %1 as great nickname).
Finally, I got the solution:
Environment
- WindowsXP
- Python 2.6 installed at c:\Python26
Installation
- Zorba 1.2 or 1.4 installed to standard location
- Path to Zorba bin as first item in
PATH
- both files from Zorba bin\python (
zorba_api.py
and_zorba_api.pyd
) moved toC:\Python26\LIB\site-packages
As result, I was able to run C:\Program Files\Zorba XQuery Processor 1.4.0\share\doc\zorba-1.4.0\python\examples\python_test.py
from any folder in my computer, even without the python line, modifying PATH
NB:
- PATH problem might be related to too long string there.
- Process Monitor was of good help finding, which DLL cannot be loaded
精彩评论