python Python下的XQuery库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2133648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XQuery library under Python
提问by Ooki
Is there any existing way to run XQuery under python? (not starting to build a parser yourself in other words).
是否有任何现有的方法可以在 python 下运行 XQuery?(换句话说,不是自己开始构建解析器)。
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.
我有大量的遗留 XQuery,我想将它们移植到我们的新系统,或者更确切地说,我想移植框架而不是 XQuery。
Therefore: Is there any library that allows me to run XQuery under python?
因此:是否有任何库可以让我在 python 下运行 XQuery?
采纳答案by Aiden Bell
Sort of ...
有点 ...
Looking through the W3C implementations list for XQuerythere is:
- Python bindings for Zorba
- Sednais a free native XML database with API for Python.
- Zorba 的 Python 绑定
- Sedna是一个免费的原生 XML 数据库,带有Python 的API 。
A few Python examples with Zorba, from here
Zorba 的一些 Python 示例,来自这里
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.
该列表中可能有 C 实现,可以很容易地绑定到 Python。希望这会有所帮助,看到如此少的实现让我有些惊讶。虽然,XQuery 并不是我认为最需要的 XML 工具。
回答by kohsah
回答by vadim
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!
Zorba 1.2 从 python 工作。安装后你会在 zorba 文件夹下得到一个 python 文件夹。将其附加到 sys.path,还有 zorba\bin 文件夹。在所有操作导入“zorba_api”之后就可以了!
回答by Jan Vlcinsky
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).
我遇到了像 Ted 这样的问题,并尝试使用来自 vadim 的答案。但是,我仍然无法正确加载 zorba_api,抱怨“ImportError DLL 加载失败”(不知道是哪一个,使用 %1 作为很好的昵称)。
Finally, I got the solution:
最后,我得到了解决方案:
Environment
环境
- WindowsXP
- Python 2.6 installed at c:\Python26
- 视窗XP
- Python 2.6 安装在 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
- Zorba 1.2 或 1.4 安装到标准位置
- Zorba bin 作为第一个项目的路径
PATH
- Zorba bin\python (
zorba_api.py
和_zorba_api.pyd
) 中的两个文件都移至C:\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
结果,C:\Program Files\Zorba XQuery Processor 1.4.0\share\doc\zorba-1.4.0\python\examples\python_test.py
即使没有 python 行,我也可以从计算机中的任何文件夹运行,修改 PATH
NB:
注意:
- PATH problem might be related to too long string there.
- Process Monitorwas of good help finding, which DLL cannot be loaded
- PATH 问题可能与那里的字符串太长有关。
- Process Monitor可以很好地帮助查找无法加载哪个 DLL