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

落花浮王杯 提交于 2019-12-13 15:27:13

问题


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.


回答1:


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.




回答2:


This is the new official XQuery 3.0 syntax, which is already supported by some XQuery implementations (so I guess it will be implemented in Zorba soon?):

declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:omit-xml-declaration "yes";
"your query"



回答3:


According to the docs ( http://www.zorba-xquery.com/html/documentation/2.1.0/zorba/indexpage#w3cspecs ) Zorba should support the Serialization spec ( http://www.w3.org/TR/xslt-xquery-serialization/#serparam ). In that case it should, if I am not mistaken, be:

declare option omit-xml-declaration "yes";

HTH!




回答4:


I think zorba doesn't use options to set serialisation parameters. Instead, you'll have to set those parameters as parameters of the serialisation function you're using.

For example, to serialize some XML to a file using zorba 2.x, you culd use the file:write() function. This function takes three parameters:

  • the file to write to,
  • the content to write,
  • and the serialisation parameters:

EDIT: I think it would look like this:

file:write (
    '/tmp/test.xml', 
    $content, 
    <serialization-parameters>
        <omit-xml-declaration>yes</omit-xml-declaration>
    </serialization-parameters> 
)

This is similar to zorba's 1.4.0 version that offered a generic function ser:serialize() in the serialize module. In general, this is not only application-specific but also version-specific so it may be helpful to know the zorba version you're using.

EDIT: If you're using the command line utility, you can use the option --serialization-parameter, -z to set serialisation parameters:

zorba -z omit-xml-declaration=yes -f -q my_xquery.xq


来源:https://stackoverflow.com/questions/9312593/xquery-and-zorba-setting-the-serialization-parameters-from-inside-the-xquery-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!