Project

Profile

Help

Returning an XDM map from XQuery works but from XPath seems to fail with Python API of SaxonC 11.1

Added by Martin Honnen about 2 years ago

I am trying a simple example to return an XDM map as a result of an XPath evaluation from SaxonC 11.1 using Python:

from saxonc import *

with PySaxonProcessor(license=False) as proc:
    print("Test SaxonC on Python")
    print(proc.version)
    
    xpath_processor = proc.new_xpath_processor()
        
    result = xpath_processor.evaluate('map { "value" : 1, "cat": "test", "check" : false() }')
    
    if result is None and xpath_processor.exception_occurred:
        print(xpath_processor.error_message)
    
    print(isinstance(result, PyXdmValue))
    
    result1 = result.head
	
    print(isinstance(result1, PyXdmItem))
    
    print(isinstance(result1, PyXdmMap))
    
    print(result1)

I don't get an error but I fail to get a PyXdmMap:

Test SaxonC on Python
SaxonC-HE 11.1 from Saxonica
True
True
False
Traceback (most recent call last):
  File "C:\Users\marti\OneDrive\Documents\xslt\blog-xslt-3-by-example\saxonc-11.1-python\arrays-and-maps\returnXdmMapFromXPathTest2.py", line 22, in <module>
    print(result1)
TypeError: __str__ returned non-string (type NoneType)

A similar XQuery evaluation does return a PyXdmMap, it seems (even if it fails to output a string value of a map) as

from saxonc import *

with PySaxonProcessor(license=False) as proc:
    print("Test SaxonC on Python")
    print(proc.version)
    
    xquery_processor = proc.new_xquery_processor()
    
    result = xquery_processor.run_query_to_value(query_text = 'map { "value" : 1, "cat": "test", "check" : false() }')
    
    if result is None and xquery_processor.exception_occurred:
        print(xquery_processor.error_message)

    print(isinstance(result, PyXdmValue))
	
    result1 = result.head
	
    print(isinstance(result1, PyXdmItem))

    print(isinstance(result1, PyXdmMap))
        
    print(result1)

outputs

Test SaxonC on Python
SaxonC-HE 11.1 from Saxonica
True
True
True
Traceback (most recent call last):
  File "C:\Users\marti\OneDrive\Documents\xslt\blog-xslt-3-by-example\saxonc-11.1-python\arrays-and-maps\returnXdmMapFromXQueryTest1.py", line 22, in <module>
    print(result1)
TypeError: __str__ returned non-string (type NoneType)

Any hints? Or is that not completely implemented for XPath?


Replies (2)

RE: Returning an XDM map from XQuery works but from XPath seems to fail with Python API of SaxonC 11.1 - Added by O'Neil Delpratt about 2 years ago

Thanks for reporting the issues you have found with the XdmMap. I will use the following bug issue to keep track: #5298

RE: Returning an XDM map from XQuery works but from XPath seems to fail with Python API of SaxonC 11.1 - Added by O'Neil Delpratt about 2 years ago

The Underlying C++ API for XPathProcessor is wrong. We check for instance of XdmFunctionItem before checking the subclasses first: i.e. XdmMap and XdmArray. The XQueryProcessor has the correct logic.

The other failure is the toString method for XdmMap across all processors.

    (1-2/2)

    Please register to reply