|
import os
|
|
import re
|
|
import sys
|
|
import traceback
|
|
|
|
import xml.etree.ElementTree as et
|
|
|
|
root = os.path.abspath(os.path.dirname(__file__))
|
|
saxon_path = os.path.join(root, 'saxon')
|
|
sys.path.append(saxon_path)
|
|
|
|
import saxonc
|
|
|
|
xq = open('/home/mrslow/dev/scripts_py3/without_func_call.xquery').read()
|
|
|
|
fc = open('/home/mrslow/dev/scripts_py3/test.xml').read()
|
|
tree = et.fromstring(fc)
|
|
fc = et.tostring(tree, encoding='utf-8').decode()
|
|
# print(fc)
|
|
|
|
|
|
with saxonc.PySaxonProcessor(license=False) as proc:
|
|
print('Creating new xquery processor -> ', end='')
|
|
xqp = proc.new_xquery_processor()
|
|
print('OK')
|
|
xqp.clear_properties()
|
|
xqp.clear_parameters()
|
|
print(f'Prepare xml -> ', end='')
|
|
xml = proc.parse_xml(xml_text=fc)
|
|
print('OK')
|
|
print('Prepare xquery -> ', end='')
|
|
xqp.set_query_content(xq)
|
|
print('OK')
|
|
print('Setup context -> ', end='')
|
|
xqp.set_context(xdm_item=xml)
|
|
print('OK')
|
|
print('Setup `$document` variable -> ', end='')
|
|
xqp.set_parameter(name='$document', value=xml)
|
|
print('OK')
|
|
print('Running XQuery -> ')
|
|
res = xqp.run_query_to_string()
|
|
print(res)
|
|
if res is None:
|
|
err_count = xqp.exception_count()
|
|
for index in range(err_count):
|
|
print(xqp.get_error_message(index+1))
|
|
xqp.clear_properties()
|