JSON字符串数组中的MarkLogic TDE Xpath值 [英] MarkLogic TDE Xpath values from JSON string array

查看:112
本文介绍了JSON字符串数组中的MarkLogic TDE Xpath值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用原始ID的行和数组的每个值构建一个tde.

I want to build a a tde with a row with an id and each value of an array in the original document.

我为每个元素获得一行,但值均为null并被忽略.

I get a row for each element but the values are null and ignored.

似乎如果上下文设置为不是数组的任何内容,那么../uri可以工作,但是当上下文为数组时永远不会.

Seems if the context is set to anything not an array the ../uri works but never when the context is an array.

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

I am struggling to find good resources for MarkLogic TDE other than simplistic examples,

示例文档(摘要)

 "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"
                }
            }
        }
    ]
    }

推荐答案

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

The expression /node() for the type column will attempt to get child nodes of the text node containing your type, but a text node doesn't have any child nodes. data() or . is more appropriate.

uri 列的表达式 ../uri 在树上的位置不够高.要获得类型值的完整MarkLogic XPath将是/object-node()/object-node('instance')/array-node('types')/text().您需要上升两个级别才能从周围的数组节点中逃脱.它可以帮助将/instance/types 重写为/instance/array-node()/types :

The expression ../uri for the uri column does not go up the tree high enough. The full MarkLogic XPath to get to your type values would be /object-node()/object-node('instance')/array-node('types')/text(). You need to go up two levels to escape from the surrounding array-node. It can help to rewrite /instance/types to /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!

这篇关于JSON字符串数组中的MarkLogic TDE Xpath值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆