Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何编写代码来处理MarkLogic 7和8中JSON API的差异?_Json_Xquery_Marklogic - Fatal编程技术网

如何编写代码来处理MarkLogic 7和8中JSON API的差异?

如何编写代码来处理MarkLogic 7和8中JSON API的差异?,json,xquery,marklogic,Json,Xquery,Marklogic,MarkLogic 8在许多方面改进了JSON支持,但MarkLogic 7的一些JSON函数现在具有不同的签名或执行不同的操作。如何编写能够同时使用这两个版本的XQuery代码?到目前为止,我遇到的主要更改是将xdmp:from json、xdmp:to json和json:transfrom to json。如果您有大量来自MarkLogic 7的JSON相关代码,这些更改可能会破坏现有代码 不要直接调用那些xdmp和json函数,而是导入此库模块并从json等调用c:from json。这

MarkLogic 8在许多方面改进了JSON支持,但MarkLogic 7的一些JSON函数现在具有不同的签名或执行不同的操作。如何编写能够同时使用这两个版本的XQuery代码?

到目前为止,我遇到的主要更改是将xdmp:from json、
xdmp:to json
json:transfrom to json
。如果您有大量来自MarkLogic 7的JSON相关代码,这些更改可能会破坏现有代码

不要直接调用那些
xdmp
json
函数,而是导入此库模块并从json等调用
c:from json。这允许为MarkLogic 7编写的代码在这两个版本中都能工作

module namespace c="http://blakeley.com/marklogic/json/compatibility";

import module namespace json="http://marklogic.com/xdmp/json"
 at "/MarkLogic/json/json.xqy";

(: No prefix for the fn:* functions :)
declare default function namespace "http://www.w3.org/2005/xpath-functions";

declare variable $VERSION := xs:integer(
  substring-before(xdmp:version(), ".")) ;

declare function c:from-json(
  $arg as xs:string)
as item()*
{
  xdmp:from-json(
    if ($VERSION ge 8) then xdmp:unquote($arg, (), "format-json")
    else $arg)
};

declare function c:to-json(
  $item as item()*)
as xs:string*
{
  if ($VERSION ge 8) then xdmp:quote($item)
  else xdmp:to-json($item)
};

declare function c:transform-to-json(
  $node as node(),
  $config as map:map?)
as xs:string
{
  json:transform-to-json($node, $config) ! (
    if ($VERSION ge 8) then xdmp:quote(.)
    else .)
};

declare function c:transform-to-json(
  $node as node())
as xs:string
{
  c:transform-to-json($node, ())
};

当我遇到其他更改或听说它们时,我将扩展此功能。如果太长,我将把它移到gist或github项目。

ML8发行说明列出了所有不兼容: