简体   繁体   English

我们可以在 MarkLogic 中的 mlcp 摄取期间将默认文档 uri 替换为文档本身的值吗

[英]Can we replace the default document uri to a value from the document itself during mlcp ingestion in MarkLogic

I want to replace the default document uri of the file to a value from the file's content.我想将文件的默认文档 uri 替换为文件内容中的值。

For example - the default uri is /test/Invoice.xml例如 - 默认 uri 是 /test/Invoice.xml

I want to replace the doc uri to我想将 doc uri 替换为

/Invoice_{current date time from file from field DateCreated}.xml

The file looks like this该文件看起来像这样

<?xml version="1.0" encoding="UTF-8"?>
<Test xsi:noNamespaceSchemaLocation="file:///D:/Mapforce/Projects/schema/Test.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <ID>f1258d4ae0df43d5a1e05ce9139f0ed2</ID>
    <SystemRef>22000041</SystemRef>
    <DateCreated>2022-09-06T19:07:46.3492849+01:00</DateCreated>
    <TimeSaved>240</TimeSaved>
    <ManyReasons/>
    <SubmissionUser>System</SubmissionUser>
    <InternalBusinessUnit>Finance</InternalBusinessUnit>
    <Direction>Inbound</Direction>
</Test>

How can I do it using mlcp?我怎样才能使用 mlcp 做到这一点?

Controlling Database URIs During Ingestion在摄取期间控制数据库 URI

By default, the document URIs created by mlcp during ingestion are determined by the input source.默认情况下,mlcp 在摄取期间创建的文档 URI 由输入源确定。 The tool supports several command line options for modifying this default behavior.该工具支持多个用于修改此默认行为的命令行选项。

  • Transforming the Default URI转换默认 URI

    Use the following options to tailor the database URI of inserted documents:使用以下选项定制插入文档的数据库 URI:

    • -output_uri_replace performs one or more string substitutions on the default URI. -output_uri_replace对默认 URI 执行一个或多个字符串替换。
    • -output_uri_prefix prepends a string to the URI after substitution. -output_uri_prefix在替换后将字符串添加到 URI。
    • -output_uri_suffix appends a string to the URI after substitution. -output_uri_suffix在替换后将字符串附加到 URI。

    The -output_uri_replace option accepts a comma delimited list of regular expression and replacement string pairs. -output_uri_replace 选项接受以逗号分隔的正则表达式列表和替换字符串对。

If you are applying a custom transformation , then you can also control the URI of the document.如果您正在应用自定义转换,那么您还可以控制文档的 URI。 Inside of the transform method, set the uri property of the $content map with whatever value you want.在 transform 方法内部,将$content map 的uri属性设置为您想要的任何值。 ie map:put($content, "uri", "myCustomURI.xml") .map:put($content, "uri", "myCustomURI.xml") See: Example: Changing the URI and Document Type请参阅:示例:更改 URI 和文档类型

So, in your custom transform you could XPath to the DateCreated element and let a variable:因此,在您的自定义转换中,您可以将 XPath 转换为 DateCreated 元素并设置一个变量:

let $created := map:get($content, "value")/Test/DateCreated

and then use it to construct the desired URI (may want to normalize/format the DateCreated value for a clean URI)然后用它来构造所需的 URI(可能想要规范化/格式化 DateCreated 值以获得干净的 URI)

map:put($content, "/Invoice_"||$created||".xml")

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

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