Qt QML XQuery сортировка по убыванию

#xml #qt #xpath #qml #xquery

Вопрос:

Я использую Qt/Qml. Я хочу отсортировать запись 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>
 

Ответ №1:

Обычный 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.