从 Xquery 解析 json

发布于 2024-09-24 21:51:20 字数 1999 浏览 3 评论 0原文

我正在处理 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

此 URL 有下一个信息:

{
"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。

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

预先感谢

大卫

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

第几種人 2024-10-01 21:51:20

正确的模块导入是:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文