Permalink
Browse files

Put the generated JSON documents into a namespace (http://marklogic.c…

…om/json) to support some upcoming new features.
  • Loading branch information...
1 parent a4717bb commit 585c2304d52799f2280e16e073a4c059f4e4f9d5 @ryangrimm ryangrimm committed Jun 29, 2011
Showing with 351 additions and 163 deletions.
  1. +10 −0 config/endpoints.xqy
  2. +3 −3 data/kvquery.xqy
  3. +1 −1 data/lib/common.xqy
  4. +128 −128 data/lib/json-query.xqy
  5. +28 −28 data/lib/json.xqy
  6. +1 −1 data/lib/manage.xqy
  7. +178 −0 data/lib/properties.xqy
  8. +2 −2 data/manage/field.xqy
View
@@ -43,6 +43,16 @@ declare variable $endpoints:ENDPOINTS as element(rest:options) :=
<http method="PUT"/>
<http method="DELETE"/>
</request>
+
+ <!--
+ <request uri="^/data/manage/range/([A-Za-z0-9-]+)(/)?$" endpoint="/data/manage/range.xqy" user-params="allow">
+ <uri-param name="name" as="string">$1</uri-param>
+ <http method="GET"/>
+ <http method="POST"/>
+ <http method="PUT"/>
+ <http method="DELETE"/>
+ </request>
+ -->
</options>;
declare function endpoints:options(
View
@@ -42,14 +42,14 @@ let $end :=
let $query := cts:and-query(
for $key in xdmp:get-request-field-names()
where not(starts-with($key, "__MLJSONURL__:"))
- return cts:element-value-query(xs:QName(json:escapeNCName($key)), xdmp:get-request-field($key))
+ return cts:element-value-query(xs:QName(concat("json:", json:escapeNCName($key))), xdmp:get-request-field($key))
)
let $results :=
if(exists($start) and exists($end) and $end > $start)
- then cts:search(/json, $query)[$start to $end]
+ then cts:search(/json:json, $query)[$start to $end]
else if(exists($start))
- then cts:search(/json, $query)[$start]
+ then cts:search(/json:json, $query)[$start]
else ()
let $total :=
View
@@ -42,7 +42,7 @@ declare function common:error(
};
declare function common:outputMultipleDocs(
- $docs as element(json)*,
+ $docs as element(json:json)*,
$start as xs:integer,
$end as xs:integer?,
$total as xs:integer
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -52,15 +52,15 @@ declare default function namespace "http://www.w3.org/2005/xpath-functions";
:)
declare function json:jsonToXML(
$json as xs:string
-) as element(json)
+) as element(json:json)
{
let $tokens := json:tokenize($json)
let $value := json:parseValue($tokens, 1)
let $test :=
if(xs:integer($value/@position) != fn:count($tokens) + 1)
then json:outputError($tokens, xs:integer($value/@position), "Unhandled tokens")
else ()
- return <json>{ $value/(@type, @boolean), $value/node() }</json>
+ return <json:json>{ $value/(@type, @boolean), $value/node() }</json:json>
};
(:
@@ -109,11 +109,11 @@ declare function json:xmlToJSON(
:)
declare function json:document(
$value as item()
-) as element(json)
+) as element(json:json)
{
- <json>{
+ <json:json>{
json:untypedToJSONType($value)/(@*, node())
- }</json>
+ }</json:json>
};
(:
@@ -133,7 +133,7 @@ declare function json:document(
:)
declare function json:object(
$keyValues as item()*
-) as element(item)
+) as element(json:item)
{
let $keys := map:map()
let $check :=
@@ -149,30 +149,30 @@ declare function json:object(
map:put($keys, string($i), true())
)
return
- <item type="object">{
+ <json:item type="object">{
for $key at $pos in $keyValues
return
if($pos mod 2 != 0)
- then element { json:escapeNCName($key) } { json:untypedToJSONType($keyValues[$pos + 1])/(@*, node()) }
+ then element { xs:QName(concat("json:", json:escapeNCName($key))) } { json:untypedToJSONType($keyValues[$pos + 1])/(@*, node()) }
else ()
- }</item>
+ }</json:item>
};
declare function json:o(
$keyValues as item()*
-) as element(item)
+) as element(json:item)
{
json:object($keyValues)
};
declare function json:object(
-) as element(item)
+) as element(json:item)
{
json:object(())
};
declare function json:o(
-) as element(item)
+) as element(json:item)
{
json:object(())
};
@@ -193,29 +193,29 @@ declare function json:o(
:)
declare function json:array(
$items as item()*
-) as element(item)
+) as element(json:item)
{
- <item type="array">{
+ <json:item type="array">{
for $item in $items
return json:untypedToJSONType($item)
- }</item>
+ }</json:item>
};
declare function json:a(
$items as item()*
-) as element(item)
+) as element(json:item)
{
json:array($items)
};
declare function json:array(
-) as element(item)
+) as element(json:item)
{
json:array(())
};
declare function json:a(
-) as element(item)
+) as element(json:item)
{
json:array(())
};
@@ -230,9 +230,9 @@ declare function json:a(
json:object(("foo", json:null())) -> {"foo": null}
:)
declare function json:null(
-) as element(item)
+) as element(json:item)
{
- <item type="null"/>
+ <json:item type="null"/>
};
@@ -241,12 +241,12 @@ declare function json:null(
:)
declare private function json:untypedToJSONType(
$value as item()?
-) as element(item)
+) as element(json:item)
{
- <item>{
+ <json:item>{
if(exists($value))
then
- if($value instance of element(item) or $value instance of element(json))
+ if($value instance of element(json:item) or $value instance of element(json:json))
then $value/(@*, node())
else if($value instance of xs:boolean and $value = true())
then attribute boolean { "true" }
@@ -258,7 +258,7 @@ declare private function json:untypedToJSONType(
then (attribute type { "string" }, string($value))
else (attribute type { "string" }, xdmp:quote($value))
else attribute type { "null" }
- }</item>
+ }</json:item>
};
declare private function json:processElement(
@@ -329,7 +329,7 @@ declare private function json:parseArray(
let $value := json:parseValue($tokens, $index)
let $set := xdmp:set($finalLocation, xs:integer($value/@position))
let $test := json:shouldBeOneOf($tokens, $finalLocation, ("comma", "rsquare"), "Expected either a comma or closing array")
- return <item>{ $value/(@type, @boolean), $value/node() }</item>
+ return <json:item>{ $value/(@type, @boolean), $value/node() }</json:item>
return <value type="array" position="{ $finalLocation }">{ $items }</value>
};
@@ -369,7 +369,7 @@ declare private function json:parseObject(
let $set := xdmp:set($finalLocation, xs:integer($value/@position))
let $test := json:shouldBeOneOf($tokens, $finalLocation, ("comma", "rbrace"), "Expected either a comma or closing object")
- return element { $key } { $value/(@type, @boolean), $value/node() }
+ return element { xs:QName(concat("json:", $key)) } { $value/(@type, @boolean), $value/node() }
return <value type="object" position="{ $finalLocation }">{ $items }</value>
};
@@ -476,7 +476,7 @@ declare private function json:outputObject(
) as xs:string*
{
"{",
- for $child at $pos in $element/*
+ for $child at $pos in $element/json:*
return (
if($pos = 1) then () else ",",
'"', json:unescapeNCName(fn:local-name($child)), '":', json:processElement($child)
@@ -489,7 +489,7 @@ declare private function json:outputArray(
) as xs:string*
{
"[",
- for $child at $pos in $element/*
+ for $child at $pos in $element/json:item
return (
if($pos = 1) then () else ",",
json:processElement($child)
View
@@ -27,7 +27,7 @@ declare default function namespace "http://www.w3.org/2005/xpath-functions";
declare function manage:fieldDefinitionToJsonXml(
$field as element(db:field)
-) as element(item)
+) as element(json:item)
{
json:object((
"name", string($field/db:field-name),
Oops, something went wrong.

0 comments on commit 585c230

Please sign in to comment.