Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to use XML source as a data type, not a list model?
Forum Updated to NodeBB v4.3 + New Features

How to use XML source as a data type, not a list model?

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fool
    wrote on last edited by
    #1

    Many times XML source we got is more like a single data type, like this:
    @<user>
    <name>fool</name>
    <age>18</age>
    </user>@

    But XmlListModel is used for XML source which is a collection of data types:
    @<users>
    <user>
    <name>fool</name>
    <age>18</age>
    </user>
    <user>
    <name>fool2</name>
    <age>19</age>
    </user>
    </users>@

    XmlListModel is great for representing data collections, but is there a XmlData like this:
    @XmlData {
    id: data
    source: "http://www.mysite.com/user.xml"

     XmlRole { name: "name"; query: "name/string()" }
     XmlRole { name: "age"; query: "age/int()" }
    

    }@

    So I can use it like a normal object:
    @Text {
    text: data.name
    }@

    Is there a solution for this in QML? I know I can use a C++ object to do it, but it requires quite a lot of work and is less clean.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbrasser
      wrote on last edited by
      #2

      Hi,

      There isn't an element like this yet, but it is one we'd like to add. For reference, the task for this is "QTBUG-12953":http://bugreports.qt.nokia.com/browse/QTBUG-12953.

      As a workaround, you may be able to use XmlListModel with "get":http://doc.qt.nokia.com/4.7-snapshot/qml-xmllistmodel.html#get-method to work with the data as though it were a "list of one element".

      Regards,
      Michael

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved