marklogic-9 - MarkLogic - Xpath on JSON document
问题描述
MarkLogic Version: 9.0-6.2
I am trying to apply Xpath in extract-document-data (using Query Options) on a JSON document shown below. I need to filter out "Channel" property if the underneath property "OptIn" has a value of "True".
{
"Category":
{
"Name": "Severe Weather",
"Channels":[
{
"Channel":
{
"Name":"Email",
"OptIn": "True"
}
},
{
"Channel":
{
"Name":"Text",
"OptIn": "False"
}
}
]
}
}
I tried below code,
'<extract-document-data selected="include">' +
'<extract-path>//*[OptIn="True"]/../..</extract-path>' +
'</extract-document-data>' +
which is only pulling from "Channel" property as shown below.
[
{
"Channel": {
"Name": "Email",
"OptIn": "True"
}
}
]
But my need is to pull from parent "Category" property, but filter out the Channels that have OptIn value as False.
Any pointers?
解决方案
If I understand correctly, you'd like to extract 'Category', but only with those 'Channel's that have 'OptIn' equalling 'true', right?
Extract-document-data is not advanced enough for that. You best extract entire Categories which have at least one OptIn equalling true (//Category[//OptIn = 'true']), and use a REST transform on the search response to trim down the unwanted Channels..
HTH!
推荐阅读
- excel - Excel - 刷新所有重复的数据透视表属性
- java - 无法在 android 中更新我的 Realm 数据库
- python - 列表理解问题中的赋值表达式范围
- python - 在 Pymongo 中动态构建 mongoDB 查询
- unicode - utf8编码让我很困惑
- flutter - 无法从 Future 返回对象列表
- python - 如何同时转义 Python 和 Postgres SQL 中的保留字?
- java - 如何使用 Spring Boot 实现最多一次交付消费者语义
- c++ - 指针和 PROGMEM 的问题
- jquery - 在 React 门户中执行 Jquery