2013-08-20 60 views
0

我将twitter的JSON搜索输出加载到Marklogic中,使用基本变换器将其转换为Marklogic的JSON XML格式。Marklogic Json Xquery无法查询

当我尝试使用下面的XQuery

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) 

它不断抱怨没有结果查询的ID。

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

下面是从JSON输出产生Marklogic从Twitter

<?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> 
... 

回答

3

你想选择是在你需要在你的XPath指定一个命名空间中的元素的XML的代码段;试试这个:

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) 
1

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

xdmp:describe(
    doc()[1]) 

namespace-uri(
    doc()[1]/*)