【问题标题】:Errors when trying to apply transform to search results尝试将转换应用于搜索结果时出错
【发布时间】:2017-07-18 21:35:29
【问题描述】:

编辑:我做了更多的调试,当我尝试安装转换而不是使用它时,实际上抛出了这个错误。但是,当我搜索我的数据库时,我可以在那里找到脚本。

我正在使用 Java API 和 Marklogic 版本 8。

我编写了一个 xquery 转换来在搜索检索到文档时对其进行修改。我在查询控制台中编写了它,验证它是否符合我的要求,但现在我将它保存在一个文件中并尝试在我的应用程序中使用它,我收到以下错误:

服务器消息:RESTAPI-INVALIDCONTENT: (err:FOER0000) 无效内容:无效的 xml_to_string 扩展名:xml_to_string 要么不是有效模块,要么在 http://marklogic.com/rest-api/transform/xml_to_string 命名空间中不提供扩展功能(转换)

我按照文档非常接近逐字逐句地介绍了如何安装和使用转换,所以我不太确定问题出在哪里,除了可能在脚本本身中。代码如下:

xquery version "1.0-ml";
module namespace xmlTrans =
  "http://marklogic.com/rest-api/transform/xml_to_string";

declare function xmlTrans:xmlToString(
  $context as map:map,
  $params as map:map,
  $fullDoc as document-node()
) as document-node()
{
  if(fn:empty($fullDoc/*)) then $fullDoc
  else (
    let $root  := $fullDoc/*
    let $contentArray := $root/contents
    return document
    {
      element {fn:name($root)}
      {
        $root/@*, $root/element()[fn:not(fn:name(.) eq "contents")],
        element contents
        {
          for $contentEle in $contentArray/content

          return(
            if($contentEle/@type = "paragraph") then (<content type="paragraph"><paragraph>{xdmp:quote($contentEle/paragraph/*)}</paragraph></content> )
            else ($contentEle)
          )

        }
      }
    }
  )
};

我的语法有什么问题导致 Marklogic 无法将其识别为转换吗?

【问题讨论】:

    标签: marklogic marklogic-8


    【解决方案1】:

    REST API 扩展遵循约定优于配置的方法。

    转换扩展必须包含一个名为“transform”的函数——参见:

    http://docs.marklogic.com/guide/rest-dev/transforms#id_17421

    此外,即使检测到错误,REST API 也会安装扩展。

    希望澄清,

    【讨论】:

    • 我在文档和 Google 上花费了数小时,但不知何故错过了这一点。我想尖叫。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2020-09-22
    • 1970-01-01
    • 1970-01-01
    • 2017-04-12
    • 2021-12-08
    • 1970-01-01
    • 1970-01-01
    • 2014-12-14
    相关资源
    最近更新 更多