serializationparametersxqueryzorba

XQuery and Zorba: Setting the serialization parameters from inside the XQuery document


According to this:

http://www.xmlplease.com/xquery-xhtml

"XQuery does not have a standard way of setting the serialization parameters if available. In XQuery we must look up the proper documentation for the XQuery processor to find out what serialization parameters are implemented if any, and how exactly to use them. If available they can normally be set at the command line. Often they can also be used from inside the XQuery document."

In Saxon you can write something like

declare option saxon:output "omit-xml-declaration=yes";

But there is no mention on how to do it in Zorba XQuery. Can you help? Thank you.


Solution

  • Zorba doesn't implement the XQuery 3.0 prolog options for serialization, yet.

    The only way to configure the serializer is using the command line interface (e.g. --omit-xml-declaration) or a host language (e.g. the C++ API).

    XQuery_t lQuery = aZorba->compileQuery("for $i in (1 to 3) return <a> { $i } </a>");
    
    Zorba_SerializerOptions lSerOptions;
    lSerOptions.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_YES;
    
    lQuery->execute(std::cout, &lSerOptions);
    

    Alternatively, you could explicitly serialize the result to a string

    fn:serialize($result,
      <output:serialization-parameters>
        <output:indent value="yes"/>
        <output:method value="xml"/>
        <output:omit-xml-declaration value="yes"/>
      </output:serialization-parameters>
    )
    

    and then use the text serialization method (--serialize-text) in the command line interface to output this string.