1

I am trying to run the example 24-12 in Priscilla Walmsley's XQuery book.

xquery version "3.1";
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization"; 
declare option output:method "json";
declare option output:indent "yes";
map {
   "number": 557,
   "props":
     <props>
       <length>31</length>
     </props>
}

I am getting the error 'Cannot add a map to a tree'. Why does this not work? Is there a configuration issue?

I am running this in <oXygen/> XML Editor version 19.1.

Loren Cahlander
  • 1,257
  • 1
  • 10
  • 24
  • 1
    It might be a problem with oXygen, when I try your code directly with Saxon 9.8 HE it does not give any error message but output the JSON. I am not sure oXygen is yet up to the task of creating and displaying the various new formats introduced with XSLT/XPath/XQuery 3 respectively 3.1 – Martin Honnen Nov 17 '17 at 13:00
  • 2
    I think that with oXygen if you set the output options of your XQuery transformation scenario to `open in editor` then it will at least show you the result in an editor pane instead of giving that error message. It seems with the usual output window they try to serialize as XML and the result of your query does not fit into that approach. – Martin Honnen Nov 17 '17 at 13:07
  • That worked. Thanks! I do know that when I run XQuery code in MarkLogic through oXygen that it does come out as JSON. – Loren Cahlander Nov 17 '17 at 13:14
  • Yes, it's a configuration issue. I don't know the specifics of how this runs in oXygen, but it's clear that the application is running the query in such a way that the result is being serialized as XML, which is failing. One answer is to invoke serialization within the query itself using the fn:serialize function. – Michael Kay Nov 17 '17 at 21:56
  • I will add an issue on the Oxygen XML Editor internal issues list, see how we work with Saxon and find out more about why this problem occurs. – Radu Coravu Nov 20 '17 at 07:09
  • 2
    Coming back to this after a little bit of investigation, if you edit the XQuery transformation scenario that you are using, in the "Output" tab you should uncheck the "Present as sequence" checbox as Oxygen (using a Saxon "net.sf.saxon.event.TreeReceiver" underneath) is not able to present a map as a tree-like sequence. We'll see what we can do about it. – Radu Coravu Nov 20 '17 at 14:19

0 Answers0