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



  • 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.



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.