Parse json from Xquery
I am working on the XML project and I have a problem when I try to connect a json file in my Xquery.
I will explain my problem with more details:
I do not know how to read a json file in Xquery, I got a URL(this URL has a json file) in Xquery, and that URL is the next:
http://discomap.eea.europa.eu/ArcGIS/rest/services/Admin/EuroBoundaries_Dyna_WGS84/MapServer/2/query?text=&geometry=16.4027431529776,57.0126631873995&geometryType=esriGeometryPoint&inSR=&spatialRel=esriSpatialRelIntersects&where=&returnGeometry=false&outSR=&outFields=NUTS_CODE&f=json
This URL has the next information:
{
"displayFieldName":"ICC",
"fieldAliases":{
"ICC":"ICC",
"NUTS_CODE":"NUTS_CODE"
},
"features":[{
"attributes":{
"ICC":"SE",
"NUTS_CODE":"SE21"
}
}]
}
So, I have to read this json file in Xquery or getting a function to convert this json file to xml file.
Through internet I got this code:
We import json module where they are the functions, but the URL below does not work so it is impossible to parse this function.
import module namespace json ="http://www.zorba-xquery.com/zorba/json-functions";
declare function xmlconv:RestWEB()
{
let $var := "&"
let $datocor1 := "16.4027431529776,"
let $datocor2 := "57.0126631873995"
let $dat1 := concat("geometry=",$datocor1, $datocor2)
let $dat2 := "geometryType=e开发者_高级运维sriGeometryPoint"
let $dat3 := "inSR="
let $dat4 := "spatialRel=esriSpatialRelIntersects"
let $dat5 := "where="
let $dat6 := "returnGeometry=false"
let $dat7 := "outSR="
let $dat8 := "outFields=NUTS_CODE"
let $dat9 := "f=json"
let $URLinicial := concat($var,$dat1,$var,$dat2,$var,$dat3,$var,$dat4,$var,$dat5,$var,$dat6,$var,$dat7,$var,$dat8,$var,$dat9)
let $URLFinal := concat($restWeb2,$URLinicial)
let $FinalResult := json:parse((doc($URLFinal)))
return
<div>
{$FinalResult}
</div>
};
As you can see, json:parse((doc($URLFinal)))
is the function that I try to parse the json file to xml file, but it is impossible to execute because I can not to import the modules from this page: www.zorba-xquery.com/zorba/json-functions.
Let me know if you know some function to resolve this problem or you need more information.
Thanks in advance
David
The correct module import is:
import module namespace json ="http://www.zorba-xquery.com/modules/json";
Please check out Zorba JSON documentation: http://www.zorba-xquery.com/doc/zorba-1.2.0/zorba/xqdoc/xhtml/com/zorba-xquery/www/modules/json.html
On 28msec website, you can find an example of web application written in XQuery which is using these functions: http: //www.28msec.com/support_templates_json_jsonml/index
精彩评论