Project

Profile

Help

Is there some way to have the Python API see an XdmlItem which is an XdmNode as an XdmNode without explicitly using get_node_value?

Added by Martin Honnen over 4 years ago

When looking at the Python API of Saxon-C 1.2.1 so far I find it cumbersome that it seems to be necessary to cast an XdmItem which is an XdmNode explicitly to a node with the help of https://www.saxonica.com/saxon-c/doc/html/saxonc.html#PyXdmItem-get_node_value.

Somehow, when using scripting languages like JavaScript or Python with class hierarchies I am used to the automagic downcasting through the engine and/or the API to the lowest class/type in the hierarchy.

For instance, when I try to use JavaScript of the GraalVM against the net.sf.saxon.options.cpp.XQueryEngine and run code like xdmSequence = xqueryEngine.executeQueryToValue('.', ['qs'], ['1, <foo/>']) and then access the two items in the returned sequence with e.g.

> xdmSequence.itemAt(0)
JavaObject[net.sf.saxon.s9api.XdmAtomicValue]

and

> xdmSequence.itemAt(1)
JavaObject[net.sf.saxon.s9api.XdmNode]

then the script engine knows when it as an atomic value or a node and allows me to use the relevant, specific API without any explicit cast.

I understand the situation with the Saxon-C Python API is much more complex with some hierarchy of types in Java, some in C++, then in Python but I wonder whether the current required explicit cast is due to limitations of that complex setup or whether there are some changes possible in the Python/CPython API configuration and/or implementation to script an XdmItem which is an XdmNode as an XdmNode without having to call get_node_value.


Replies (1)

RE: Is there some way to have the Python API see an XdmlItem which is an XdmNode as an XdmNode without explicitly using get_node_value? - Added by O'Neil Delpratt over 4 years ago

Indeed this is cumbersome. There is no real why we cannot downcast the XdmItem object returned from item_at function in the Python API to the lowest class/type in the hierarchy. I have created a bug issue to investigate this issue #4416

We should also make this change in the C++ and PHP APIs.

    (1-1/1)

    Please register to reply