【问题标题】:Marklogic Json Xquery can't queryMarklogic Json Xquery 无法查询
【发布时间】:2013-08-20 09:41:36
【问题描述】:

我将 twitter 的 JSON 搜索输出加载到 Marklogic 中,并使用基本转换器将其转换为 Marklogic 的 JSON XML 格式。

当我尝试使用以下 XQuery 查询 id 时

xquery version "1.0-ml";
declare namespace html = "http://www.w3.org/1999/xhtml";
for $r in doc()/json
let $b:=$r/id
return (
$b)

它一直抱怨没有结果。

当我使用 doc() 时,xml 显示正常,但 doc()/json 不显示任何内容。

以下是 Marklogic 从 Twitter 的 JSON 输出生成的 XML 的 sn-p

<?xml version="1.0" encoding="UTF-8"?>
<json type="object" xmlns="http://marklogic.com/xdmp/json/basic">
  <contributors type="null"/>
  <truncated type="boolean">false</truncated>
  <text type="string">@angelicism I love this site: http://t.co/XIjckcu0Lk</text>
  <in__reply__to__status__id type="number">369589929183297536</in__reply__to__status__id>
  <id type="number">369595664277065728</id>
  <favorite__count type="number">0</favorite__count>
...

【问题讨论】:

    标签: json xquery marklogic


    【解决方案1】:

    您尝试选择的元素位于您需要在 XPath 中指定的命名空间中;试试这个:

    xquery version "1.0-ml";
    declare namespace html = "http://www.w3.org/1999/xhtml";
    declare namespace json = "http://marklogic.com/xdmp/json/basic";
    for $r in doc()/json:json
    let $b:=$r/json:id
    return (
    $b)
    

    【讨论】:

      【解决方案2】:

      它可能是命名空间,也可能是二进制节点。有用的调试工具包括xdmp:describefn:namespace-uri

      xdmp:describe(
        doc()[1])
      
      namespace-uri(
        doc()[1]/*)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-08-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多