tags:

views:

596

answers:

3

Hey Is 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?

+3  A: 

Sort of ...

Looking through the W3C implementations list for XQuery there is:

  1. Python bindings for Zorba
  2. Sendna, but might not be what you're after

A few Python examples with Zobra, 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.

Aiden Bell
Yeah Zobra seems to be what I was looking for, thanks :)
Ooki
A: 

Has anyone had any success using Zorba with Python? I've tried installing Zorba 1.0 but not all the libraries seem available so that it works with Python. Can anyone help?

Ted
A: 

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!

vadim