Home · All Classes · All Functions · Overviews

QML XmlListModel Element Reference

The XmlListModel element is used to specify a model using XPath expressions. More...

Properties

Methods

Detailed Description

XmlListModel is used to create a model from XML data that can be used as a data source for the view classes (such as ListView, PathView, GridView) and other classes that interact with model data (such as Repeater).

Here is an example of a model containing news from a Yahoo RSS feed:

 XmlListModel {
     id: feedModel
     source: "http://rss.news.yahoo.com/rss/oceania"
     query: "/rss/channel/item"
     XmlRole { name: "title"; query: "title/string()" }
     XmlRole { name: "pubDate"; query: "pubDate/string()" }
     XmlRole { name: "description"; query: "description/string()" }
 }

You can also define certain roles as "keys" so that the model only adds data that contains new values for these keys when reload() is called.

For example, if the roles above were defined like this:

     XmlRole { name: "title"; query: "title/string()"; isKey: true }
     XmlRole { name: "pubDate"; query: "pubDate/string()"; isKey: true }

Then when reload() is called, the model will only add new items with a "title" and "pubDate" value combination that is not already present in the model.

This is useful to provide incremental updates and avoid repainting an entire model in a view.


Property Documentation

read-onlycount : int

The number of data entries in the model.


namespaceDeclarations : string

A set of declarations for the namespaces used in the query.


read-onlyprogress : real

This property holds the progress of data source loading, from 0.0 (nothing loaded) to 1.0 (finished).

See also status.


query : string

An absolute XPath query representing the base query for the model items. The query should start with '/' or '//'.


read-onlyroles : list<XmlRole>

The roles to make available for this model.


source : url

The location of the XML data source.

If both source and xml are set, xml will be used.


read-onlystatus : enum

This property holds the status of data source loading. It can be one of:

See also progress.


xml : string

This property holds XML text set directly.

The text is assumed to be UTF-8 encoded.

If both source and xml are set, xml will be used.


Method Documentation

XmlListModel::reload ()

Reloads the model.

If no key roles have been specified, all existing model data is removed, and the model is rebuilt from scratch.

Otherwise, items are only added if the model does not already contain items with matching key role values.



Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies) Trademarks
Qt 4.7.0