将字符串转换为 Marklogic Xquery 中的元素
Converting string to element in Marklogic Xquery
我有以下 XQuery 脚本,它基本上将属性添加到 MarkLogic 中的现有文档:
xquery version "1.0-ml";
declare namespace xhtml = "http://www.w3.org/1999/xhtml";
declare namespace error="http://marklogic.com/xdmp/error";
declare namespace cdata = "http://www.w3.org/1999/cdata";
declare variable $uri as xs:string external;
declare variable $contentproperties as xs:string external;
xdmp:document-add-properties($uri, ( $contentproperties ) );
外部 C# 程序调用此查询并将以下内容作为 $contentproperties
的字符串传递:
<Title>My Title</Title>,<Date>1629076218</Date>,<SubjectArea>My subject</SubjectArea>,<ContentType>My content type</ContentType>,<Summary>My summary</Summary>
但是,错误 returns 提到:
XDMP-ARGTYPE: (err:XPTY0004) xdmp:document-add-properties("", "My Title,1629076218,My ...") -- arg2 is not of type element()*"
我应该如何将 xs:string
转换为 element()*
类型?
引用文档添加属性方法:https://docs.marklogic.com/xdmp:document-add-properties
您可以tokenize()
that string of comma separated values, then use xdmp:unquote()
将XML 字符串解析为XML 文档,然后对元素进行XPath。将该元素序列分配给另一个变量,并使用该变量设置您的属性:
xquery version "1.0-ml";
declare namespace xhtml = "http://www.w3.org/1999/xhtml";
declare namespace error="http://marklogic.com/xdmp/error";
declare namespace cdata = "http://www.w3.org/1999/cdata";
declare variable $uri as xs:string external := "test";
declare variable $contentproperties as xs:string external := "<Title>My Title</Title>,<Date>1629076218</Date>,<SubjectArea>My subject</SubjectArea>,<ContentType>My content type</ContentType>,<Summary>My summary</Summary>";
declare variable $contentproperties-element as element()* := tokenize($contentproperties, ",") ! xdmp:unquote(.)/*;
xdmp:document-add-properties($uri, ( $contentproperties-element ) );
我有以下 XQuery 脚本,它基本上将属性添加到 MarkLogic 中的现有文档:
xquery version "1.0-ml";
declare namespace xhtml = "http://www.w3.org/1999/xhtml";
declare namespace error="http://marklogic.com/xdmp/error";
declare namespace cdata = "http://www.w3.org/1999/cdata";
declare variable $uri as xs:string external;
declare variable $contentproperties as xs:string external;
xdmp:document-add-properties($uri, ( $contentproperties ) );
外部 C# 程序调用此查询并将以下内容作为 $contentproperties
的字符串传递:
<Title>My Title</Title>,<Date>1629076218</Date>,<SubjectArea>My subject</SubjectArea>,<ContentType>My content type</ContentType>,<Summary>My summary</Summary>
但是,错误 returns 提到:
XDMP-ARGTYPE: (err:XPTY0004) xdmp:document-add-properties("", "My Title,1629076218,My ...") -- arg2 is not of type element()*"
我应该如何将 xs:string
转换为 element()*
类型?
引用文档添加属性方法:https://docs.marklogic.com/xdmp:document-add-properties
您可以tokenize()
that string of comma separated values, then use xdmp:unquote()
将XML 字符串解析为XML 文档,然后对元素进行XPath。将该元素序列分配给另一个变量,并使用该变量设置您的属性:
xquery version "1.0-ml";
declare namespace xhtml = "http://www.w3.org/1999/xhtml";
declare namespace error="http://marklogic.com/xdmp/error";
declare namespace cdata = "http://www.w3.org/1999/cdata";
declare variable $uri as xs:string external := "test";
declare variable $contentproperties as xs:string external := "<Title>My Title</Title>,<Date>1629076218</Date>,<SubjectArea>My subject</SubjectArea>,<ContentType>My content type</ContentType>,<Summary>My summary</Summary>";
declare variable $contentproperties-element as element()* := tokenize($contentproperties, ",") ! xdmp:unquote(.)/*;
xdmp:document-add-properties($uri, ( $contentproperties-element ) );