从Xquery解析json

时间:2010-09-27 10:03:36

标签: json xquery

我正在处理XML项目,当我尝试在Xquery中连接json文件时遇到问题。

我将用更多细节解释我的问题:

我不知道如何在Xquery中读取json文件,我在Xquery中得到了一个URL(此URL有一个json文件),该URL是下一个:

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

此网址包含以下信息:

{
"displayFieldName":"ICC",
"fieldAliases":{
      "ICC":"ICC",
      "NUTS_CODE":"NUTS_CODE"
            },
"features":[{
      "attributes":{
            "ICC":"SE",
            "NUTS_CODE":"SE21"
                  }
            }]
}

所以,我必须在Xquery中读取这个json文件或者获取一个函数将这个json文件转换为xml文件。

通过互联网我得到了这段代码:

我们导入json模块它们是函数,但是下面的URL不起作用,所以不可能解析这个函数。

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=esriGeometryPoint"
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>
};

正如您所看到的,json:parse((doc($URLFinal)))是我尝试将json文件解析为xml文件的函数,但是无法执行,因为我无法从此页面导入模块:www.zorba- xquery.com/zorba/json-functions。

如果您知道解决此问题的某些功能,或者您需要更多信息,请与我们联系。

提前致谢

大卫

1 个答案:

答案 0 :(得分:1)

正确的模块导入是:

import module namespace json =“http://www.zorba-xquery.com/modules/json”;

请查看Zorba JSON文档:http://www.zorba-xquery.com/doc/zorba-1.2.0/zorba/xqdoc/xhtml/com/zorba-xquery/www/modules/json.html

在28msec的网站上,您可以找到使用这些函数在XQuery中编写的Web应用程序示例:http://www.28msec.com/support_templates_json_jsonml/index