2015-02-06 1 views

ответ

4

До сих пор основные изменения, с которыми я столкнулся, составляют xdmp:from-json, xdmp:to-json и json:transfrom-to-json. Если у вас есть справедливое количество кода JSON от MarkLogic 7, эти изменения могут нарушить существующий код.

Вместо вызова этих xdmp и 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,()) 
}; 

Я продолжу это, когда буду сталкиваться с другими изменениями или слышать о них. Если он будет слишком длинным, я переведу его в проект gistub или github.

+1

В примечаниях к выпуску ML8 перечислены все несовместимости: http://docs.marklogic.com/guide/relnotes/chap4#id_92312 – grtjn