QML XmlListModel ElementThe XmlListModel element is used to specify a read-only model using XPath expressions. More... This element was introduced in Qt 4.7. Properties
MethodsDetailed DescriptionXmlListModel is used to create a read-only model from XML data. It can be used as a data source for view elements (such as ListView, PathView, GridView) and other elements that interact with model data (such as Repeater). For example, if there is a XML document at http://www.mysite.com/feed.xml like this: <?xml version="1.0" encoding="utf-8"?> <rss version="2.0"> ... <channel> <item> <title>A blog post</title> <pubDate>Sat, 07 Sep 2010 10:00:01 GMT</pubDate> </item> <item> <title>Another blog post</title> <pubDate>Sat, 07 Sep 2010 15:35:01 GMT</pubDate> </item> </channel> </rss> A XmlListModel could create a model from this data, like this: import QtQuick 1.0 XmlListModel { id: xmlModel source: "http://www.mysite.com/feed.xml" query: "/rss/channel/item" XmlRole { name: "title"; query: "title/string()" } XmlRole { name: "pubDate"; query: "pubDate/string()" } } The query value of "/rss/channel/item" specifies that the XmlListModel should generate a model item for each <item> in the XML document. The XmlRole objects define the model item attributes. Here, each model item will have title and pubDate attributes that match the title and pubDate values of its corresponding <item>. (See XmlRole::query for more examples of valid XPath expressions for XmlRole.) The model could be used in a ListView, like this: ListView { width: 180; height: 300 model: xmlModel delegate: Text { text: title + ": " + pubDate } } The XmlListModel data is loaded asynchronously, and status is set to XmlListModel.Ready when loading is complete. Note this means when XmlListModel is used for a view, the view is not populated until the model is loaded. Using key XML rolesYou can define certain roles as "keys" so that when reload() is called, the model will only add and refresh data that contains new values for these keys. For example, if above role for "pubDate" was defined like this instead: XmlRole { name: "pubDate"; query: "pubDate/string()"; isKey: true } Then when reload() is called, the model will only add and reload items with a "pubDate" value that is not already present in the model. This is useful when displaying the contents of XML documents that are incrementally updated (such as RSS feeds) to avoid repainting the entire contents of a model in a view. If multiple key roles are specified, the model only adds and reload items with a combined value of all key roles that is not already present in the model. See also RSS News. Property DocumentationThe number of data entries in the model. The namespace declarations to be used in the XPath queries. The namespaces should be declared as in XQuery. For example, if a requested document at http://mysite.com/feed.xml uses the namespace "http://www.w3.org/2005/Atom", this can be declared as the default namespace: XmlListModel { source: "http://mysite.com/feed.xml" query: "/feed/entry" namespaceDeclarations: "declare default element namespace 'http://www.w3.org/2005/Atom';" XmlRole { name: "title"; query: "title/string()" } } This indicates the current progress of the downloading of the XML data source. This value ranges from 0.0 (no data downloaded) to 1.0 (all data downloaded). If the XML data is not from a remote source, the progress becomes 1.0 as soon as the data is read. Note that when the progress is 1.0, the XML data has been downloaded, but it is yet to be loaded into the model at this point. Use the status property to find out when the XML data has been read and loaded into the model. An absolute XPath query representing the base query for creating model items from this model's XmlRole objects. The query should start with '/' or '//'. Specifies the model loading status, which can be one of the following:
See also progress. This property holds the XML data for this model, if set. The text is assumed to be UTF-8 encoded. If both source and xml are set, xml is used. Method DocumentationReturns a string description of the last error that occurred if status is XmlListModel::Error. Returns the item at index in the model. For example, for a model like this: XmlListModel { id: model source: "http://mysite.com/feed.xml" query: "/feed/entry" XmlRole { name: "title"; query: "title/string()" } } This will access the title value for the first item in the model: var title = model.get(0).title; 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. See also Using key XML roles and XmlRole::isKey. |
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.8 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com