Hi,
we've recently updated BaseX from 10.5 to 10.6 and it seems there was some change in the namespace declaration behavior.
Example:
declare function local:list() as element()+ { ( <string>1</string>, <string>2</string>, <string>3</string> ) };
declare function local:to-json() as element() { <map xmlns="http://www.w3.org/2005/xpath-functions"> <string key="id">id</string> <array key="list">{local:list()}</array> </map> };
local:to-json()
Output 10.5:
<map xmlns="http://www.w3.org/2005/xpath-functions"> <string key="id">id</string> <array key="list"> <string>1</string> <string>2</string> <string>3</string> </array> </map>
Output 10.6:
<map xmlns="http://www.w3.org/2005/xpath-functions"> <string key="id">id</string> <array key="list"> <string xmlns="">1</string> <string xmlns="">2</string> <string xmlns="">3</string> </array> </map>
The empty namespace attributes are added when the elements are created with a function and not directly in the context of the parent element.
Was this intended and if yes is there a switch to get the old behavior back?
Best Regards Johannes
Hi Johannes,
This was a known bug in the previous version, the new behavior is correct:
The elements in the user-defined function have no namespace, and by inserting them as child nodes, the namespace must not be changed.
Things work differently if the node constructors are defined within the curly braces. The namespace context of the ancestors will be applied to the constructed nodes:
<a xmlns='x'>{ <b/> }</a>
So you’ll either need to get rid of the additional function, or you can use the 'map' prefix. As it’s statically defined in BaseX, you can omit the xmlns:map declaration:
declare function local:list() { <string>1</string> }; map:map{ local:list() }</map:map>
Hope this helps, Christian
basex-talk@mailman.uni-konstanz.de