exist
exist copied to clipboard
[BUG] xml-to-json() ignores namespace requirement
Describe the bug
The description of the xml-to-json() function in the XPath and XQuery Functions and Operators 3.1 spec states that:
The first argument
$inputis a node; the subtree rooted at this node will typically be the XML representation of a JSON document as defined in 17.4.2 XML Representation of JSON.
That definition says that:
the phrase "an element named N" is to be interpreted as meaning "an element node whose local name is N and whose namespace URI is http://www.w3.org/2005/xpath-functions".
The xml-to-json() function in eXist-db transforms XML map and array markup to JSON even when the namespace is omitted. <oXygen/> raises an error if the XML elements to be transformed are not in the required namespace.
Expected behavior
I expect eXist-db to raise an error if the XML elements to be transformed by the xml-to-json() function are not in the required namespace.
To Reproduce
Create the following XQuery and run in eXide and in the <oXygen/> XQuery debugger. It will succeed in both. Then remove the namespace declaration and rerun. The code will succeed (incorrectly) in eXide and raise an error (correctly) in <oXygen/>:
let $doc :=
<array
key="stooges"
xmlns="http://www.w3.org/2005/xpath-functions">
<string>Curly</string>
<string>Larry</string>
<string>Moe</string>
</array>
return
fn:xml-to-json($doc)
Context (please always complete the following information)
Build: eXist-6.2.0 (c8fa4958b6d4a50bd0cba7f3e76a150226414187) Java: 1.8.0_333 (Oracle Corporation) OS: Mac OS X 12.7.6 (x86_64)
Additional context
- How is eXist-db installed? [e.g. JAR installer, DMG, … ]: DMG
- Any custom changes in e.g.
conf.xml?: No