[Qt-qml] Error querying root item of XmlListModel

Adriano Rezende adriano.rezende at openbossa.org
Wed Oct 19 02:32:43 CEST 2011


I've created an extended element to handle more complex XML files some
time ago. The syntax is like the following:

XmlPathModel {
    source: "foo.xml"
    query: "/foo/bar"

    XmlPathRole {
        name: "sum"
        query: "totalSum"
        type: XmlPathRole.Real
    }

    XmlPathRole {
        name: "books"
        query: "books/book"
        type: XmlPathRole.Group

        XmlPathRole {
            name: "title"
            query: "title"
            type: XmlPathRole.String
        }

        XmlPathRole {
            name: "authors"
            query: "authors/author"
            type: XmlPathRole.Group

            XmlPathRole {
                name: "name"
                query: "name"
                type: XmlPathRole.String
            }
        }
    }
}

I'll push a version more aligned with the current XmlListModel, so
others can use it in the meanwhile. It does not provide advanced XPath
features like sum() operators or individual array access, but it can
handle most of the XML files, providing a QAbstractItemModel tree
after parsing.

Br,
Adriano

On Tue, Oct 18, 2011 at 8:05 PM,  <bea.lam at nokia.com> wrote:
> Actually, the more relevant task here is probably https://bugreports.qt.nokia.com/browse/QTBUG-13688, "Support lists of lists in XmlListModel".
>
> On 18/10/2011, at 6:32 PM, ext bea.lam at nokia.com wrote:
>
>> On 18/10/2011, at 1:25 AM, ext Girish Ramakrishnan wrote:
>>
>>> Hi,
>>> Someone on irc was having trouble with the XmlListModel and I was
>>> trying to help him/her out. I don't know xquery/xpath well enough to
>>> know if this is a problem with my example or xmlpatterns. So, I
>>> reduced the problem to this: http://pastebin.com/Gdmc2Gzq works but
>>> http://pastebin.com/pMnvFYQQ doesn't. Basically, if I query anything
>>> directly under the root element, XmlListModel just reports an error.
>>> Querying any level one below the root element, it works fine.
>>
>>
>> To confirm, this is because this XML data in http://pastebin.com/pMnvFYQQ has multiple "Category" objects:
>>
>> <?xml version="1.0" encoding="utf-8"?>
>> <MediaList>
>>    <Category name="name1">Something here</Category>
>>    <Category name="name2">Something there</Category>
>> </MediaList>
>>
>>
>> Since there are multiple query items, it doesn't know which one to fetch. The query should be "Category[1]/@name/string()" to fetch the exact index, or it should use a model that puts the query at "MediaList/Category" instead.
>>
>> Related to this is https://bugreports.qt.nokia.com/browse/QTBUG-12953 which suggests being able to create an XmlObject to cater for list objects.
>>
>>
>> regards,
>>
>> Bea
>>
>> _______________________________________________
>> Qt-qml mailing list
>> Qt-qml at qt.nokia.com
>> http://lists.qt.nokia.com/mailman/listinfo/qt-qml
>
> _______________________________________________
> Qt-qml mailing list
> Qt-qml at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-qml
>


More information about the Qt-qml mailing list