2013-08-20 50 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]/*)