我有以下xml: -
<?xml version="1.0" encoding="UTF-8"?>
<patent-assignment>
<assignment-record>
<correspondent>
<name>NORTH AMERICA INTERNATIONAL PATENT OFFIC</name>
<address-1>P.O. BOX 506</address-1>
<address-2>MERRIFIELD, VA 22116</address-2>
</correspondent>
</assignment-record>
<patent-assignors>
<patent-assignor>
<name>TSAI, YU-WEN</name>
<execution-date>
<date>20050331</date>
</execution-date>
</patent-assignor>
<patent-assignor>
<name>HUANG, CHENG-I</name>
<execution-date>
<date>20050331</date>
</execution-date>
</patent-assignor>
</patent-assignors>
<patent-assignees>
<patent-assignee>
<name>FARADAY TECHNOLOGY CORP.</name>
<address-1>NO.10-2, LI-HSIN ROAD 1, SCIENCE-BASED INDUSTRIAL PARK</address-1>
<city>HSIN-CHU CITY</city>
<country-name>TAIWAN</country-name>
</patent-assignee>
</patent-assignees>
</patent-assignment>
现在在将文档加载到Marklogic时,我想将专利转让人的元素名称更改为assignor-name,将patent-assignee的元素名称更改为assignee-name,但我想用Record Loader加载数据而不是使用Marklogic的Information Studio。如何使用Record Loader执行此操作?
答案 0 :(得分:3)
您需要设置CONTENT_FACTORY_CLASSNAME=com.marklogic.recordloader.xcc.XccModuleContentFactory
并编写XQuery模块以实现内容模块。 http://marklogic.github.com/recordloader/有一个示例模块,您可以自定义。您的转换代码将放在local:do()
函数中,替换示例“小写元素localnames”代码:
xquery version "1.0-ml";
declare variable $URI as xs:string external;
declare variable $XML-STRING as xs:string external;
declare variable $NAMESPACE as xs:string external;
declare variable $LANGUAGE as xs:string external;
declare variable $ROLES-EXECUTE as xs:string external;
declare variable $ROLES-INSERT as xs:string external;
declare variable $ROLES-READ as xs:string external;
declare variable $ROLES-UPDATE as xs:string external;
declare variable $COLLECTIONS as xs:string external;
declare variable $SKIP-EXISTING as xs:boolean external;
declare variable $ERROR-EXISTING as xs:boolean external;
declare variable $FORESTS as xs:string external;
declare function local:do($list as node()*)
as node()*
{
for $n in $list return typeswitch($n)
(: lower-case element localnames :)
case element() return element {
QName(namespace-uri($n), lower-case(local-name($n)))
} {
$n/@*, local:do($n/node())
}
case document-node() return document { local:do($n/node()) }
default return $n
};
if ($SKIP-EXISTING and doc($URI)) then ()
else if ($ERROR-EXISTING and doc($URI)) then error((), 'DUPLICATE-URI', $URI)
else xdmp:document-insert(
$URI,
local:do(xdmp:unquote(
$XML-STRING,
$NAMESPACE,
if ($LANGUAGE) then concat('default-language=', $LANGUAGE) else ()
)),
(
for $r in tokenize($ROLES-EXECUTE, ',')[. ne '']
return xdmp:permission('execute', $r),
for $r in tokenize($ROLES-INSERT, ',')[. ne '']
return xdmp:permission('insert', $r),
for $r in tokenize($ROLES-READ, ',')[. ne '']
return xdmp:permission('read', $r),
for $r in tokenize($ROLES-UPDATE, ',')[. ne '']
return xdmp:permission('update', $r)
),
tokenize($COLLECTIONS, ',')[. ne ''],
0,
for $id in tokenize($FORESTS, ',')[. ne '']
return xs:unsignedLong($id)
)