【问题标题】:MarkLogic TDE Xpath values from JSON string array来自 JSON 字符串数组的 MarkLogic TDE Xpath 值
【发布时间】:2019-10-31 23:05:47
【问题描述】:

我想构建一个 tde,其中一行有一个 id 和原始文档中一个数组的每个值。

我为每个元素获取一行,但值为 null 并被忽略。

如果上下文设置为任何不是数组的东西,../uri 就可以工作,但当上下文是数组时则不会。

除了简单的示例之外,我正在努力为 MarkLogic TDE 寻找好的资源,

示例文档 (sn-p)

 "instance": {
        "uri": "/A/Uri/of/some/type.json", 
         "types": [
          "a", 
          "b", 
          "c"
      ]
}

模板

{
  "template":{
    "context":"/instance/types",
    "collections":["Collection"],
    "enabled" : true,
    "rows":[
      {
        "schemaName":"namespace",
        "viewName":"uri2types",
        "columns":[
          {
            "name":"uri",
            "scalarType":"anyURI",
            "val":"../uri",
            "nullable":true,
            "invalidValues": "ignore"
          }
          ,
          {
            "name":"type",
            "scalarType":"string",
            "val":"/node()",
            "nullable":true,
            "invalidValues": "ignore"
          }
        ]
      }
    ]
  }
}

结果

     {
        "/A/Uri/of/some/type.json": [
            {
                "row": {
                    "schema": "namespace", 
                    "view": "uri2types", 
                    "data": {
                        "rownum": "1"
                }
            }
        }, 
            {
                "row": {
                    "schema": "namespace", 
                    "view": "uri2types", 
                    "data": {
                        "rownum": "2"
                }
            }
        }, 
            {
                "row": {
                "schema": "namespace", 
                "view": "uri2types", 
                "data": {
                    "rownum": "3"
                }
                }
            }
        ]
        }

**Result Wanted** 


    {
        "/A/Uri/of/some/type.json": [
        {
            "row": {
                    "schema": "namespace", 
                    "view": "uri2types", 
                    "data": {
                        "rownum": "1",
                        "uri":"/A/Uri/of/some/type.json":,
                        "type"="a"

                    }
                }
            }, 
        {
            "row": {
                "schema": "namespace", 
                "view": "uri2types", 
                "data": {
                    "rownum": "2",
                    "uri":"/A/Uri/of/some/type.json":,
                    "type":"b"
                }
            }
        }, 
        {
            "row": {
                "schema": "namespace", 
                "view": "uri2types", 
                "data": {
                    "rownum": "3",
                    "uri":"/A/Uri/of/some/type.json":,
                    "type":"c"
                }
            }
        }
    ]
    }

【问题讨论】:

    标签: arrays xpath marklogic tde


    【解决方案1】:

    type 列的表达式/node() 将尝试获取包含您的类型的文本节点的子节点,但文本节点没有任何子节点。 data(). 更合适。

    uri 列的表达式../uri 没有上到足够高的树。获取类型值的完整 MarkLogic XPath 将是 /object-node()/object-node('instance')/array-node('types')/text()。您需要上两层才能逃离周围的数组节点。将/instance/types重写为/instance/array-node()/types会有所帮助:

    'use strict';
    
    let json = xdmp.toJSON({
      "instance": {
        "uri": "/A/Uri/of/some/type.json", 
        "types": [
          "a", 
          "b", 
          "c"
        ]
      }
    });
    let tpl = xdmp.toJSON({
      "template":{
        "context":"/instance/array-node()/types",
        "enabled" : true,
        "rows":[
          {
            "schemaName":"namespace",
            "viewName":"uri2types",
            "columns":[
              {
                "name":"uri",
                "scalarType":"anyURI",
                "val":"../../uri",
                "nullable":true,
                "invalidValues": "ignore"
              }
              ,
              {
                "name":"type",
                "scalarType":"string",
                "val":"data()",
                "nullable":true,
                "invalidValues": "ignore"
              }
            ]
          }
        ]
      }
    });
    tde.validate([tpl]);
    tde.nodeDataExtract([json], [tpl]);
    

    HTH!

    【讨论】:

    • 谢谢你解决了它。 Data() 和 .有效,但我确信我以前尝试过双路径。
    【解决方案2】:

    我认为问题出在:"val":"/node()",。您给出的路径从根开始,而不是上下文节点。试试这个:

    "val":".",
    

    【讨论】:

    • 是的,解决了出现的类型,但我仍然看不到 URI 数据。
    猜你喜欢
    • 2021-06-20
    • 1970-01-01
    • 2018-02-13
    • 1970-01-01
    • 2013-01-03
    • 1970-01-01
    • 2015-02-14
    • 1970-01-01
    • 2019-05-19
    相关资源
    最近更新 更多