我试图获取jQuery autocomplete小部件来从存储在Marklogic XML服务器中的XML源获取数据. XML数据非常简单,如下所示: idBank ATM/ididPostageShipping/ididWebHosting/ididClientParking/id Markllogic服务器确实有一
XML数据非常简单,如下所示:
<id>Bank ATM</id> <id>PostageShipping</id> <id>WebHosting</id> <id>ClientParking</id>
Markllogic服务器确实有一个功能xdmp:to-json应该做类似的事情,但是这样使用时
let $ex := fn:collection()//ex:Expense return xdmp:to-json($ex/ex:id)
它返回看起来像那样的输出
["fn:doc("/expenses/Expenses-Combined.xml")/ex:Expenses/ex:Expense[1]/ex:id", "fn:doc("/expenses/Expenses-Combined.xml")/ex:Expenses/ex:Expense[2]/ex:id", "fn:doc("/expenses/Expenses-Combined.xml")/ex:Expenses/ex:Expense[3]/ex:id", "fn:doc("/expenses/Expenses-Combined.xml")/ex:Expenses/ex:Expense[4]/ex:id", "fn:doc("/expenses/Expenses-Combined.xml")/ex:Expenses/ex:Expense[5]/ex:id"]
我为XQuery尝试了其他jSon序列化程序
> https://github.com/isubiker/mljson
> https://github.com/marklogic/commons
并且他们都有返回非常复杂的json结构的问题,而不是jQuery的自动完成小部件将采用的简单数组.有人会提出什么建议吗?
https://github.com/isubiker/mljson
怎么样:xquery version "1.0-ml"; let $ids := <ids> <id>Bank ATM</id> <id>PostageShipping</id> <id>WebHosting</id> <id>ClientParking</id> </ids> return xdmp:to-json(fn:data($ids/id)) ==> ["Bank ATM", "PostageShipping", "WebHosting", "ClientParking"]
您可能希望使用FLWOR遍历集合,并替换& lt; ids& gt;在上面的示例中使用& lt; ex:Expense& gt;