xml - Qt QML XQuery 按降序排序
问题描述
我正在使用 Qt/Qml。我想使用 Query 按降序对 XML 记录进行排序。我该如何编写这种排序查询?
这是我获取列表和查询道具的 QML 项目
XmlListModel {
id: xmlModel
source: "record.xml"
query: "/catalog/* [sort($id as item()*)]"
XmlRole { name: "id"; query: "id/string()" }
}
假设的 Xml 示例:
<?xml version="1.0"?>
<catalog>
<booke >
<id>1</id>
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</booke>
<bookz >
<id>2</id>
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</bookz>
<bookd >
<id>3</id>
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-11-17</publish_date>
<description>After the collapse of a nanotechnology
society in England, the young survivors lay the
foundation for a new society.</description>
</bookd>
</catalog>
解决方案
正常的 XQuery 1(如果我还记得的话)将类似于
for $item in catalog/*
order by xs:integer($item/id) descending
return $item
sort
我认为在 XQuery/XPath 3.0 之前没有引入函数。在那里你可以使用sort(catalog/*, (), function($item) { -$item/id })
.
我不知道 qt 支持什么,但我宁愿猜测 XQuery 1 而不是 3。
推荐阅读
- c - 如何正确设置 OpenCL?
- typescript - 根据 TypeScript 中的参数值更改返回类型
- python - Python 2.7.15 MongoDb 身份验证失败
- elixir - Elixir - 连接和匹配组合
- r - 按传递给函数的列名对数据框进行排序
- javascript - bundle.js 不使用 webpack 构建
- python - python将字符串(Mar18)转换为日期格式(201803)
- python - EOFError - 使用 ftplib 上传 .csv 文件
- javascript - AngularJs - 在表格中设置单选按钮值
- asp.net-mvc - 在类库中引用 MVC Core RemoteAttribute