Reputation: 73
I loaded twitter's JSON's search output into Marklogic transforming it into Marklogic's JSON XML format using the basic transformer.
When i try to query for the id using the following 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)
it keeps complaining that there are no results.
When i use doc() the xml displays fine but doc()/json dosen't display anything.
Below is a snippet of the XML that Marklogic generated from the JSON output from 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>
...
Upvotes: 1
Views: 257
Reputation: 7840
It's probably namespaces, or possibly a binary node. Useful tools for debugging include xdmp:describe
and fn:namespace-uri
.
xdmp:describe(
doc()[1])
namespace-uri(
doc()[1]/*)
Upvotes: 1
Reputation: 1040
The elements you're trying to select are in a namespace that you need to specify in your XPaths; try this:
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)
Upvotes: 3