java - XML 节点替换失败

标签 java xslt nosql xquery marklogic

我尝试Corb在大量文档中搜索和更新节点:

示例输入:

<hcmt xmlns="http://horn.thoery">
  <susceptible>X</susceptible>
  <reponsible>foresee–intervention</reponsible>
  <intend>Benefit Protagonist</intend>
  <justified>Goal Outwiegen</justified>
</hcmt> 

Xquery:

(: let $resp   :=  "foresee–intervention" :)
 
let $docs :=    
  cts:search(doc(),
  cts:and-query((
  cts:collection-query("hcmt"),
  cts:path-range-query("/horn:hcmt/horn:responsible", "=", $resp)
        ))
    )
return
  for $doc in $docs
return
  xdmp:node-replace($doc/horn:hcmt/horn:responsible, "Foresee Intervention")

预期输出:

<hcmt xmlns="http://horn.thoery">
  <susceptible>X</susceptible>
  <reponsible>Foresee Intervention</reponsible>
  <intend>Benefit Protagonist</intend>
  <justified>Goal Outwiegen</justified>
</hcmt>

但是 Corb 中没有发生节点替换,并且没有错误返回。其他查询在 Corb 中工作正常。节点替换如何在 Corb 中正常工作?

预先感谢您的帮助。

最佳答案

I create functions to reconcile the encoding matters. This not only mitigates potential API transaction failures but also is a requisite to validate & encode parameter or element/property/uri name.

That said, a sample MarkLogic Java API implementation is:

  1. 在文件系统中创建一个动态查询构造,在我的例子中,product-query-option.xml(直接使用查询值:Chooser–Option)<
<search xmlns="http://marklogic.com/appservices/search">
    <query>
        <and-query>
            <collection-constraint-query>
                <constraint-name>Collection</constraint-name>
                <uri>proto</uri>
            </collection-constraint-query>
            <range-constraint-query>
                <constraint-name>ProductType</constraint-name>
                <value>Chooser–Option</value>
            </range-constraint-query>
        </and-query>
    </query>
</search>
  • 将持久查询选项部署到模块数据库,在我的例子中,search-lexis.xml,选项文件如下:
  • <options xmlns="http://marklogic.com/appservices/search">
         <constraint name="Collection">
             <collection prefix=""/>
         </constraint>
         <constraint name="ProductType">
            <range type="xs:string" collation="http://marklogic.com/collation/en/S1">
              <path-index xmlns:prod="schema://fc.fasset/product">/prod:requestProduct/prod:_metaData/prod:productType</path-index>
            </range>
         </constraint>
    </options>
    
  • 关注 Dynamic Java Search
  •         File file = new File("src/main/resources/queryoption/product-query-option.xml");
    
            FileHandle fileHandle = new FileHandle(file);
    
            RawCombinedQueryDefinition rcqDef = queryMgr.newRawCombinedQueryDefinition(fileHandle, queryOption);
    
    • 您当然可以在 QueryDefinition 中将查询和选项合并为一个句柄。
  • 您原来的节点替换被翻译为 Java Partial Update
    • 确保 DocumentPatchBuilder setNamespaces 具有正确的 NamespaceContext
  • 对于批量数据操作,高性能方法是 MarkLogic 数据移动:使用搜索到的 Uris 实例化 QueryBatcher,提供替换值或数据片段 PatchBuilder.replaceValue ,并完成批处理 dbClient.newXMLDocumentManager().patch(uri, patchHandle);
  • MarkLogic Data Services: If you succeed above, perhaps, then go at a more robust and scalable enterprise SOA approach, please review Data Services.

    • Gradle 的实现如下:

    Data Services Implementations

    (注意,所有转换指标都应该是参数,包括路径/元素/属性名称、命名空间、值等。没有什么是硬编码的。)在 service.json 中声明的一个代理服务可以使用不同类型的模块为多个端点(在 /root/df-ds/fxd 下)提供服务,让您可以自由地开发纯 Java 或扩展开发平台来处理复杂的数据操作。

    If these operations are persistent node update, you should consider in-memory node transform before the ingestion. Besides the MarkLogic data transformation tools, you can harness the power of XSLT2+.

    Saxon XPathFactory could be a serviceable vehicle to query/transform node. Not sure if it is a reciprocity, ML Java API implements the XPath compile to split large paths and stream transaction. XSLT/Saxon is not my forte; therefore, I can’t comment how comparable it is with this encode/decode particularity or how it handles transaction (insert, update…etc) streaming.

    关于java - XML 节点替换失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69498184/

    相关文章:

    java - 从Java模板直接访问DAO

    java - JTree如何将叶节点设置为可扩展

    xml - 在 XSL 中的一个选择中调用两次 translate()

    xml - 标记化 XSLT 的优化

    mysql - MongoDB 重读,相对低写,小操作性能

    nosql - 重新生成 CouchDB View

    java - Swagger 路线在 Spring Boot + Jersey 上返回 404

    java - 采集接口(interface)

    php - 需要借助 xsl/xslt 将重复的 XML 节点放在单独的节点中

    nosql - RavenDB - 修补非规范化引用集合