Qt World Summit: Submit your Presentation

Parsing local XML file to ListModel via XmlListModel

  • Hello,
    I have a problem with the XmlListModel object. I tried to read a dummy.xml input file, which is strucutred something like this:


    <?xml version="1.0" encoding="utf-8"?>
    <title>stuff 1</title>
    <date>Sat, 07 Sep 2010 10:00:01 GMT</date>
    <title>stuff 2</title>
    <date>Sat, 07 Sep 2010 15:35:01 GMT</date>

    My QML code looks something like this:


    XmlListModel {
        id: xmlModel
        source: "file://C:/...../Dummy.xml"
        query: "/dummyroot/item"
        XmlRole { name: "title"; query: "title/string()"}
        XmlRole { name: "date"; query: "date/string()" }

    with an additional ListView added to show the data. Sadly it wont show any data, nor print model inputs via print(xmlModel.get(0).title)...
    I furthermore tested the loading state functionality via a function which looks like this:
    function do_xmldata_work()
    console.log("do_xmldata_work begin>: ")
    while(xmlModel.status != XmlListModel.Ready)
    console.log("loading xml file: " + xmlModel.status + " error Message" + xmlModel.errorString())
    console.log("loading xml file: " + xmlModel.status + " || finished")

    The status is 1 or finished, but the ListView stays empty.
    print(xmlModel.get(0).title) returns TypeError: Cannot read property 'title' of undefined

    Any help would be much appreciated!
    Thanks in advance!


Log in to reply