xml - 使用 xquery (basex) 重命名 XML 中的节点
问题描述
这是端点匹配时运行的脚本%rest:path
:
XQuery
module namespace page = 'http://basex.org/examples/web-page';
import module namespace file = "http://expath.org/ns/file";
declare %updating
%rest:path("/fnac")
%rest:POST("{$body}")
function page:fnac($body) {
file:write("fnacData.xml",$body),
db:create('prices', 'fnacData.xml', "./"),
let $update := doc('C:\Users\franc\Desktop\basex\bin\fnacData.xml')
for $n in $update//_
return rename node $n as 'smartphone',
update:output('Update Successful')
};
XML
(内容$body
)
<json type="array">
<_ type="object">
<name>Samsung Galaxy S10+</name>
<brand>Samsung</brand>
<pageUrl>https://www.fnac.pt/Samsung-Galaxy-S10-G975FZ-128GB-Verde-Telemovel-SmartPhone-Android/a6587862</pageUrl>
<price>1029.99</price>
<details>G975FZ - 128GB - Verde</details>
<imgUrl>https://static.fnac-static.com/multimedia/Images/PT/NR/ab/5c/4d/5069995/1545-1.jpg</imgUrl>
<dateTime type="number">1579132283666</dateTime>
<store>fnac</store>
</_>
<_ type="object">
<name>Xiaomi Mi 9 Lite</name>
<brand>Xiaomi</brand>
<pageUrl>https://www.fnac.pt/Smartphone-Xiaomi-Mi-9-Lite-64GB-Black-Telemovel-SmartPhone-Android/a7166673</pageUrl>
<price>339.99</price>
<details>64GB - Black</details>
<imgUrl>https://static.fnac-static.com/multimedia/Images/PT/NR/ca/73/55/5600202/1545-1.jpg</imgUrl>
<dateTime type="number">1579132283667</dateTime>
<store>fnac</store>
</
</json>
该脚本应该将节点重命名<_>
为<smartphone>
并更新 XML 文件,但我无法使其工作。它确实返回“更新成功”,但 XML 文件保持不变
解决方案
推荐阅读
- google-cloud-platform - 无法连接到 GCP VM 权限被拒绝(公钥)错误
- python - 如何在 python 字典中增加一个值?
- css - 使 flex-item 填满居中对齐的 flexbox 的整个实际宽度
- arrays - 在 TypeScript 中格式化数据库中的数据
- python - Widnows 10 上的“无法打开包含文件:'gsl/gsl_errno.h':没有这样的文件或目录”错误
- ruby-on-rails - 如何验证 HSTS 在 Rails 应用程序中是否按预期工作?
- python - .ppm 文件每 3 个像素分隔一次
- tensorflow - 张量流中的自定义层以输出其输入的运行最大值
- bazel - git repo 中非 bazel 项目的 Bazel 规则
- php - 使用 laravel 8 上传文件时不允许进行 Chmod() 操作