Python下的XQuery库 [英] XQuery library under Python

查看:30
本文介绍了Python下的XQuery库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何现有的方法可以在 python 下运行 XQuery?(换句话说,不是自己开始构建解析器).

Is there any existing way to run XQuery under python? (not starting to build a parser yourself in other words).

我有大量的遗留 XQuery 想要移植到我们的新系统,或者更确切地说,我想要移植框架而不是 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.

因此:有没有什么库可以让我在 python 下运行 XQuery?

Therefore: Is there any library that allows me to run XQuery under python?

推荐答案

...

查看 XQuery 的 W3C 实现列表,有:

  1. Zorba 的 Python 绑定
  2. Sedna 是一个免费的原生 XML 数据库,带有用于 Python.
  1. Python bindings for Zorba
  2. Sedna is a free native XML database with API for Python.

一些关于 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

该列表中可能有可以轻松绑定到 Python 的 C 实现.希望这会有所帮助,看到如此少的实现让我有些惊讶.不过,我认为 XQuery 并不是最需要的 XML 工具.

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.

这篇关于Python下的XQuery库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆