从 Google 联系人 API XML 中提取时出现 XmlListModel 问题
XmlListModel issue when fetching from the Google Contacts API XML
我正在尝试显示 Google 联系人 API XML 数据中的条目
https://developers.google.com/contacts/v3#retrieving_all_contacts
使用以下代码:
import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick.XmlListModel 2.0
Item {
width: 400
height: 300
ListView {
id: listView
anchors.fill: parent
model: model
delegate: Text {
id: name
text: qsTr("title: ") + title
}
}
XmlListModel {
id: model
xml: "<feed"
+" xmlns=\"http://www.w3.org/2005/Atom\""
+" xmlns:openSearch=\"http://a9.com/-/spec/opensearch/1.1/\""
+" xmlns:gContact=\"http://schemas.google.com/contact/2008\""
+" xmlns:batch=\"http://schemas.google.com/gdata/batch\""
+" xmlns:gd=\"http://schemas.google.com/g/2005\""
+" gd:etag=\"feedEtag\">"
+"<id>userEmail</id>"
+"<updated>2008-12-10T10:04:15.446Z</updated>"
+"<category scheme=\"http://schemas.google.com/g/2005#kind\" term=\"http://schemas.google.com/contact/2008#contact\"/>"
+"<link rel=\"http://schemas.google.com/g/2005#feed\" type=\"application/atom+xml\" href=\"https://www.google.com/m8/feeds/contacts/userEmail/full\"/>"
+"<link rel=\"http://schemas.google.com/g/2005#post\" type=\"application/atom+xml\" href=\"https://www.google.com/m8/feeds/contacts/userEmail/full\"/>"
+"<link rel=\"http://schemas.google.com/g/2005#batch\" type=\"application/atom+xml\" href=\"https://www.google.com/m8/feeds/contacts/userEmail/full/batch\"/>"
+"<link rel=\"self\" type=\"application/atom+xml\" href=\"https://www.google.com/m8/feeds/contacts/userEmail/full?max-results=25\"/>"
+"<author>"
+"<name>User</name>"
+"<email>userEmail</email>"
+"</author>"
+"<generator version=\"1.0\" uri=\"http://www.google.com/m8/feeds\">Contacts</generator>"
+"<openSearch:totalResults>1</openSearch:totalResults>"
+"<openSearch:startIndex>1</openSearch:startIndex>"
+"<openSearch:itemsPerPage>25</openSearch:itemsPerPage>"
+"<entry gd:etag=\"contactEtag\">"
+"<id>http://www.google.com/m8/feeds/contacts/userEmail/base/contactId</id>"
+"<updated>2008-12-10T04:45:03.331Z</updated>"
+"<app:edited xmlns:app=\"http://www.w3.org/2007/app\">2008-12-10T04:45:03.331Z</app:edited>"
+"<category scheme=\"http://schemas.google.com/g/2005#kind\" term=\"http://schemas.google.com/contact/2008#contact\"/>"
+"<title>Fitzwilliam Darcy</title>"
+"<gd:name><gd:fullName>Fitzwilliam Darcy</gd:fullName></gd:name>"
+"<link rel=\"http://schemas.google.com/contacts/2008/rel#photo\" type=\"image/*\" href=\"https://www.google.com/m8/feeds/photos/media/userEmail/contactId\" gd:etag=\"photoEtag\"/>"
+"<link rel=\"self\" type=\"application/atom+xml\" href=\"https://www.google.com/m8/feeds/contacts/userEmail/full/contactId\"/>"
+"<link rel=\"edit\" type=\"application/atom+xml\" href=\"https://www.google.com/m8/feeds/contacts/userEmail/full/contactId\"/>"
+"<gd:phoneNumber rel=\"http://schemas.google.com/g/2005#home\" primary=\"true\">456</gd:phoneNumber>"
+"<gd:extendedProperty name=\"pet\" value=\"hamster\"/>"
+"<gContact:groupMembershipInfo deleted=\"false\" href=\"http://www.google.com/m8/feeds/groups/userEmail/base/groupId\"/>"
+"</entry>"
+"<!-- Other entries ... -->"
+"</feed>"
query: "/feed/entry"
XmlRole { name: "title"; query: "title/string()" }
onStatusChanged: {
if (status == XmlListModel.Null) {
console.log("Null");
}
if (status == XmlListModel.Ready) {
console.log("Ready");
console.log(count);
}
if (status == XmlListModel.Loading) {
console.log("Loading");
}
if (status == XmlListModel.Error) {
console.log("Error");
console.log(errorString());
}
}
}
}
但这似乎不起作用,也没有记录任何错误。
我不知道是不是因为模式的原因,因为简单的例子一切都很好。
有什么帮助吗? :)
您必须声明命名空间,如 the docs 所示:
你的情况:
XmlListModel {
id: model
// ...
query: "/feed/entry"
XmlRole { name: "title"; query: "title/string()" }
<b>namespaceDeclarations: "declare default element namespace 'http://www.w3.org/2005/Atom';"</b>
// ...
我正在尝试显示 Google 联系人 API XML 数据中的条目 https://developers.google.com/contacts/v3#retrieving_all_contacts 使用以下代码:
import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick.XmlListModel 2.0
Item {
width: 400
height: 300
ListView {
id: listView
anchors.fill: parent
model: model
delegate: Text {
id: name
text: qsTr("title: ") + title
}
}
XmlListModel {
id: model
xml: "<feed"
+" xmlns=\"http://www.w3.org/2005/Atom\""
+" xmlns:openSearch=\"http://a9.com/-/spec/opensearch/1.1/\""
+" xmlns:gContact=\"http://schemas.google.com/contact/2008\""
+" xmlns:batch=\"http://schemas.google.com/gdata/batch\""
+" xmlns:gd=\"http://schemas.google.com/g/2005\""
+" gd:etag=\"feedEtag\">"
+"<id>userEmail</id>"
+"<updated>2008-12-10T10:04:15.446Z</updated>"
+"<category scheme=\"http://schemas.google.com/g/2005#kind\" term=\"http://schemas.google.com/contact/2008#contact\"/>"
+"<link rel=\"http://schemas.google.com/g/2005#feed\" type=\"application/atom+xml\" href=\"https://www.google.com/m8/feeds/contacts/userEmail/full\"/>"
+"<link rel=\"http://schemas.google.com/g/2005#post\" type=\"application/atom+xml\" href=\"https://www.google.com/m8/feeds/contacts/userEmail/full\"/>"
+"<link rel=\"http://schemas.google.com/g/2005#batch\" type=\"application/atom+xml\" href=\"https://www.google.com/m8/feeds/contacts/userEmail/full/batch\"/>"
+"<link rel=\"self\" type=\"application/atom+xml\" href=\"https://www.google.com/m8/feeds/contacts/userEmail/full?max-results=25\"/>"
+"<author>"
+"<name>User</name>"
+"<email>userEmail</email>"
+"</author>"
+"<generator version=\"1.0\" uri=\"http://www.google.com/m8/feeds\">Contacts</generator>"
+"<openSearch:totalResults>1</openSearch:totalResults>"
+"<openSearch:startIndex>1</openSearch:startIndex>"
+"<openSearch:itemsPerPage>25</openSearch:itemsPerPage>"
+"<entry gd:etag=\"contactEtag\">"
+"<id>http://www.google.com/m8/feeds/contacts/userEmail/base/contactId</id>"
+"<updated>2008-12-10T04:45:03.331Z</updated>"
+"<app:edited xmlns:app=\"http://www.w3.org/2007/app\">2008-12-10T04:45:03.331Z</app:edited>"
+"<category scheme=\"http://schemas.google.com/g/2005#kind\" term=\"http://schemas.google.com/contact/2008#contact\"/>"
+"<title>Fitzwilliam Darcy</title>"
+"<gd:name><gd:fullName>Fitzwilliam Darcy</gd:fullName></gd:name>"
+"<link rel=\"http://schemas.google.com/contacts/2008/rel#photo\" type=\"image/*\" href=\"https://www.google.com/m8/feeds/photos/media/userEmail/contactId\" gd:etag=\"photoEtag\"/>"
+"<link rel=\"self\" type=\"application/atom+xml\" href=\"https://www.google.com/m8/feeds/contacts/userEmail/full/contactId\"/>"
+"<link rel=\"edit\" type=\"application/atom+xml\" href=\"https://www.google.com/m8/feeds/contacts/userEmail/full/contactId\"/>"
+"<gd:phoneNumber rel=\"http://schemas.google.com/g/2005#home\" primary=\"true\">456</gd:phoneNumber>"
+"<gd:extendedProperty name=\"pet\" value=\"hamster\"/>"
+"<gContact:groupMembershipInfo deleted=\"false\" href=\"http://www.google.com/m8/feeds/groups/userEmail/base/groupId\"/>"
+"</entry>"
+"<!-- Other entries ... -->"
+"</feed>"
query: "/feed/entry"
XmlRole { name: "title"; query: "title/string()" }
onStatusChanged: {
if (status == XmlListModel.Null) {
console.log("Null");
}
if (status == XmlListModel.Ready) {
console.log("Ready");
console.log(count);
}
if (status == XmlListModel.Loading) {
console.log("Loading");
}
if (status == XmlListModel.Error) {
console.log("Error");
console.log(errorString());
}
}
}
}
但这似乎不起作用,也没有记录任何错误。 我不知道是不是因为模式的原因,因为简单的例子一切都很好。
有什么帮助吗? :)
您必须声明命名空间,如 the docs 所示:
你的情况:
XmlListModel {
id: model
// ...
query: "/feed/entry"
XmlRole { name: "title"; query: "title/string()" }
<b>namespaceDeclarations: "declare default element namespace 'http://www.w3.org/2005/Atom';"</b>
// ...