简体   繁体   English

我们可以使用 mlcp 在 MarkLogic 中的文件摄取期间更改文件的 XML 结构吗?

[英]Can we change the XML structure of a file during file ingestion in MarkLogic using mlcp?

I have a xml file to ingest in MarkLogic database where a new XML field has to be added.我有一个 xml 文件要在 MarkLogic 数据库中摄取,其中必须添加一个新的 XML 字段。 And the requirement is to add that XML field only during the mlcp import.并且要求仅在 mlcp 导入期间添加 XML 字段。 Is this possible in MarkLogic using xquery?这在 MarkLogic 中使用 xquery 可能吗?

XML file now - XML 现在归档 -

<name>rashmita</name>
<employeeType>regular</employeeType>

XML to be changed - XML待改-

<name>rashmita</name>
<employeeType>regular</employeeType>
<role>developer</role>

Yes, it is possible to modify the payload on ingest with MLCP.是的,可以在使用 MLCP 摄取时修改有效负载。

Transforming Content During Ingestion在摄取期间转换内容

You can create an XQuery or Server-Side JavaScript function and install it on MarkLogic Server to transform and enrich content before inserting it into the database.您可以创建一个 XQuery 或服务器端 JavaScript function 并将其安装在 MarkLogic Server 上,以便在将内容插入数据库之前对其进行转换和丰富。 Your function runs on MarkLogic Server.您的 function 在 MarkLogic 服务器上运行。

Function Signature Function 签名

A custom transformation is an XQuery function module that conforms to the following interface.自定义转换是符合以下接口的 XQuery function 模块。 Your function receives a single input document, described by $content, and can generate zero, one, or many output documents.您的 function 接收单个输入文档,由 $content 描述,并且可以生成零个、一个或多个 output 文档。

declare function yourNamespace:transform(
  $content as map:map,
  $context as map:map)
as map:map*

So, for your example (assuming that the actual docs are well-formed XML) could look something like:因此,对于您的示例(假设实际文档是格式正确的 XML)可能类似于:

module namespace example = "http://marklogic.com/example";
declare function example:transform(
  $content as map:map,
  $context as map:map
) as map:map*
{
  let $doc := map:get($content, "value")
  let $root := $doc/*
  let $_ :=
    if ($root)
    then 
      map:put($content, "value", 
        document { element {$root/name()} {$root/@*, $root/*, <role>developer</role>} })
    else ()
  return $content
};

Using a Custom Transformation使用自定义转换

Once you install a custom transformation function on MarkLogic Server, you can apply it to your mlcp import or copy job using the following options:在 MarkLogic 服务器上安装自定义转换 function 后,您可以使用以下选项将其应用于 mlcp 导入或复制作业:

  • transform_module - The path to the module containing your transformation. transform_module - 包含转换的模块的路径。 Required.必需的。
  • transform_namespace - The namespace of your transformation function. If omitted, no namespace is assumed. transform_namespace - 转换的名称空间 function。如果省略,则假定没有名称空间。

An example invocation setting those parameters:设置这些参数的示例调用:

mlcp.sh import -mode local -host mlhost -port 8000 -username user -password password -input_file_path /space/mlcp-test/data -transform_module /example/mlcp-transform.xqy -transform_namespace "http://marklogic.com/example" mlcp.sh import -mode local -host mlhost -port 8000 -username user -password password -input_file_path /space/mlcp-test/data -transform_module /example/mlcp-transform.xqy -transform_namespace "http://marklogic.com/例子”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM