Google Picasa API XML 反序列化 - 后续
我正在尝试编写一个类来反序列化 picasa 相册提要。到目前为止,效果非常好,获得了一些入门帮助(此处)并且我快到了。我现在有两个字段的问题。
gphoto:bytesUsed 和 gphoto:numphotosremaining 需要反序列化。我找不到任何问题。感谢您的任何建议。
Feed 网址:https://picasaweb.google.com/data/feed/api /user/{用户名}
类代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace WindowsFormsApplication4
{
[XmlType("feed", Namespace = "http://www.w3.org/2005/Atom")]
[XmlRoot("feed", Namespace = "http://www.w3.org/2005/Atom")]
public class picasa
{
[XmlAttribute]
public string id { get; set; }
[XmlAttribute]
public string title { get; set; }
[XmlAttribute]
public string icon { get; set; }
[XmlElement("link")]
public FeedLink[] links { get; set; }
[XmlElement("generator")]
public FeedGenerator generator { get; set; }
[XmlElement("author")]
public FeedAuthor author { get; set; }
[XmlElement(Namespace = "http://a9.com/-/spec/opensearch/1.1/")]
public int totalResults { get; set; }
[XmlElement("entry")]
public FeedEntry[] entries { get; set; }
[XmlType("entry", Namespace = "http://www.w3.org/2005/Atom")]
public partial class FeedEntry
{
[XmlElement]
public string id { get; set; }
[XmlElement]
public FeedCategory category { get; set; }
[XmlElement]
public string title { get; set; }
[XmlElement]
public string summary { get; set; }
[XmlElement]
public string rights { get; set; }
[XmlElement("link")]
public FeedLink[] links { get; set; }
[XmlElement("author")]
public FeedAuthor author { get; set; }
[XmlElement(ElementName = "id", Namespace = "http://schemas.google.com/photos/2007")]
public string gid { get; set; }
[XmlElement(ElementName = "name", Namespace = "http://schemas.google.com/photos/2007")]
public string gname { get; set; }
[XmlElement(ElementName = "location", Namespace = "http://schemas.google.com/photos/2007")]
public string glocation { get; set; }
[XmlElement(ElementName = "access", Namespace = "http://schemas.google.com/photos/2007")]
public string gaccess { get; set; }
[XmlElement(ElementName = "timestamp", Namespace = "http://schemas.google.com/photos/2007")]
public string gtimestamp { get; set; }
[XmlElement(ElementName = "numphotos", Namespace = "http://schemas.google.com/photos/2007")]
public int gnumphotos { get; set; }
[XmlElement(ElementName = "numphotosremaining", Namespace = "http://schemas.google.com/photos/2007")]
public int gnumphotosremaining { get; set; }
[XmlElement(ElementName = "bytesUsed", Namespace = "http://schemas.google.com/photos/2007")]
public int gbytesUsed { get; set; }
[XmlElement(ElementName = "user", Namespace = "http://schemas.google.com/photos/2007")]
public string guser { get; set; }
[XmlElement(ElementName = "nickname", Namespace = "http://schemas.google.com/photos/2007")]
public string gnickname { get; set; }
[XmlElement(ElementName = "commentingEnabled", Namespace = "http://schemas.google.com/photos/2007")]
public string gcommentingEnabled { get; set; }
[XmlElement(ElementName = "commentCount", Namespace = "http://schemas.google.com/photos/2007")]
public int gcommentCount { get; set; }
[XmlElement(ElementName = "group", Namespace = "http://search.yahoo.com/mrss/")]
public MediaGroup mgroup { get; set; }
}
#region XML types
[XmlType("author", Namespace = "http://www.w3.org/2005/Atom")]
public partial class FeedAuthor
{
[XmlElement(ElementName = "name", Namespace = "http://www.w3.org/2005/Atom")]
public string name { get; set; }
[XmlElement(ElementName = "uri", Namespace = "http://www.w3.org/2005/Atom")]
public string uri { get; set; }
}
[XmlType("category", Namespace = "http://www.w3.org/2005/Atom")]
public partial class FeedCategory
{
[XmlAttribute(AttributeName = "scheme", Namespace = "http://www.w3.org/2005/Atom")]
public string scheme { get; set; }
[XmlAttribute(AttributeName = "term", Namespace = "http://www.w3.org/2005/Atom")]
public string term { get; set; }
}
[XmlType("link", Namespace = "http://www.w3.org/2005/Atom")]
public partial class FeedLink
{
[XmlAttribute(AttributeName = "rel", Namespace = "http://www.w3.org/2005/Atom")]
public string rel { get; set; }
[XmlAttribute(AttributeName = "type", Namespace = "http://www.w3.org/2005/Atom")]
public string type { get; set; }
[XmlAttribute(AttributeName = "href", Namespace = "http://www.w3.org/2005/Atom")]
public string href { get; set; }
}
[XmlType("generator", Namespace = "http://www.w3.org/2005/Atom")]
public partial class FeedGenerator
{
[XmlAttribute(AttributeName = "version", Namespace = "http://www.w3.org/2005/Atom")]
public string version { get; set; }
[XmlAttribute(AttributeName = "uri", Namespace = "http://www.w3.org/2005/Atom")]
public string uri { get; set; }
[XmlText]
public string text { get; set; }
}
[XmlType("group", Namespace = "http://search.yahoo.com/mrss/")]
public partial class MediaGroup
{
[XmlElement(ElementName = "content", Namespace = "http://search.yahoo.com/mrss/")]
public MediaContent mgcontent { get; set; }
[XmlElement(ElementName = "credit", Namespace = "http://search.yahoo.com/mrss/")]
public string mgcredit { get; set; }
[XmlElement(ElementName = "description", Namespace = "http://search.yahoo.com/mrss/")]
public MediaDescription mgdescription { get; set; }
}
[XmlType("content", Namespace = "http://search.yahoo.com/mrss/")]
public partial class MediaContent
{
[XmlAttribute(AttributeName = "url", Namespace = "http://search.yahoo.com/mrss/")]
public string url { get; set; }
[XmlAttribute(AttributeName = "type", Namespace = "http://search.yahoo.com/mrss/")]
public string type { get; set; }
[XmlAttribute(AttributeName = "medium", Namespace = "http://search.yahoo.com/mrss/")]
public string medium { get; set; }
}
[XmlType("description", Namespace = "http://search.yahoo.com/mrss/")]
public partial class MediaDescription
{
[XmlAttribute("type", Namespace="http://search.yahoo.com/mrss/")]
public string type {get;set;}
[XmlText]
public string description { get; set; }
}
#endregion
}
}
Im trying to write a class to deserialize the picasa album feed. It has been pretty good so far, got some help to get started (here) and I'm almost there. I have a problem with two fields right now.
The gphoto:bytesUsed and gphoto:numphotosremaining want deserialize. I can't find anything wrong with it. Thankfull for any suggestions.
Url to feed: https://picasaweb.google.com/data/feed/api/user/{username}
Class code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace WindowsFormsApplication4
{
[XmlType("feed", Namespace = "http://www.w3.org/2005/Atom")]
[XmlRoot("feed", Namespace = "http://www.w3.org/2005/Atom")]
public class picasa
{
[XmlAttribute]
public string id { get; set; }
[XmlAttribute]
public string title { get; set; }
[XmlAttribute]
public string icon { get; set; }
[XmlElement("link")]
public FeedLink[] links { get; set; }
[XmlElement("generator")]
public FeedGenerator generator { get; set; }
[XmlElement("author")]
public FeedAuthor author { get; set; }
[XmlElement(Namespace = "http://a9.com/-/spec/opensearch/1.1/")]
public int totalResults { get; set; }
[XmlElement("entry")]
public FeedEntry[] entries { get; set; }
[XmlType("entry", Namespace = "http://www.w3.org/2005/Atom")]
public partial class FeedEntry
{
[XmlElement]
public string id { get; set; }
[XmlElement]
public FeedCategory category { get; set; }
[XmlElement]
public string title { get; set; }
[XmlElement]
public string summary { get; set; }
[XmlElement]
public string rights { get; set; }
[XmlElement("link")]
public FeedLink[] links { get; set; }
[XmlElement("author")]
public FeedAuthor author { get; set; }
[XmlElement(ElementName = "id", Namespace = "http://schemas.google.com/photos/2007")]
public string gid { get; set; }
[XmlElement(ElementName = "name", Namespace = "http://schemas.google.com/photos/2007")]
public string gname { get; set; }
[XmlElement(ElementName = "location", Namespace = "http://schemas.google.com/photos/2007")]
public string glocation { get; set; }
[XmlElement(ElementName = "access", Namespace = "http://schemas.google.com/photos/2007")]
public string gaccess { get; set; }
[XmlElement(ElementName = "timestamp", Namespace = "http://schemas.google.com/photos/2007")]
public string gtimestamp { get; set; }
[XmlElement(ElementName = "numphotos", Namespace = "http://schemas.google.com/photos/2007")]
public int gnumphotos { get; set; }
[XmlElement(ElementName = "numphotosremaining", Namespace = "http://schemas.google.com/photos/2007")]
public int gnumphotosremaining { get; set; }
[XmlElement(ElementName = "bytesUsed", Namespace = "http://schemas.google.com/photos/2007")]
public int gbytesUsed { get; set; }
[XmlElement(ElementName = "user", Namespace = "http://schemas.google.com/photos/2007")]
public string guser { get; set; }
[XmlElement(ElementName = "nickname", Namespace = "http://schemas.google.com/photos/2007")]
public string gnickname { get; set; }
[XmlElement(ElementName = "commentingEnabled", Namespace = "http://schemas.google.com/photos/2007")]
public string gcommentingEnabled { get; set; }
[XmlElement(ElementName = "commentCount", Namespace = "http://schemas.google.com/photos/2007")]
public int gcommentCount { get; set; }
[XmlElement(ElementName = "group", Namespace = "http://search.yahoo.com/mrss/")]
public MediaGroup mgroup { get; set; }
}
#region XML types
[XmlType("author", Namespace = "http://www.w3.org/2005/Atom")]
public partial class FeedAuthor
{
[XmlElement(ElementName = "name", Namespace = "http://www.w3.org/2005/Atom")]
public string name { get; set; }
[XmlElement(ElementName = "uri", Namespace = "http://www.w3.org/2005/Atom")]
public string uri { get; set; }
}
[XmlType("category", Namespace = "http://www.w3.org/2005/Atom")]
public partial class FeedCategory
{
[XmlAttribute(AttributeName = "scheme", Namespace = "http://www.w3.org/2005/Atom")]
public string scheme { get; set; }
[XmlAttribute(AttributeName = "term", Namespace = "http://www.w3.org/2005/Atom")]
public string term { get; set; }
}
[XmlType("link", Namespace = "http://www.w3.org/2005/Atom")]
public partial class FeedLink
{
[XmlAttribute(AttributeName = "rel", Namespace = "http://www.w3.org/2005/Atom")]
public string rel { get; set; }
[XmlAttribute(AttributeName = "type", Namespace = "http://www.w3.org/2005/Atom")]
public string type { get; set; }
[XmlAttribute(AttributeName = "href", Namespace = "http://www.w3.org/2005/Atom")]
public string href { get; set; }
}
[XmlType("generator", Namespace = "http://www.w3.org/2005/Atom")]
public partial class FeedGenerator
{
[XmlAttribute(AttributeName = "version", Namespace = "http://www.w3.org/2005/Atom")]
public string version { get; set; }
[XmlAttribute(AttributeName = "uri", Namespace = "http://www.w3.org/2005/Atom")]
public string uri { get; set; }
[XmlText]
public string text { get; set; }
}
[XmlType("group", Namespace = "http://search.yahoo.com/mrss/")]
public partial class MediaGroup
{
[XmlElement(ElementName = "content", Namespace = "http://search.yahoo.com/mrss/")]
public MediaContent mgcontent { get; set; }
[XmlElement(ElementName = "credit", Namespace = "http://search.yahoo.com/mrss/")]
public string mgcredit { get; set; }
[XmlElement(ElementName = "description", Namespace = "http://search.yahoo.com/mrss/")]
public MediaDescription mgdescription { get; set; }
}
[XmlType("content", Namespace = "http://search.yahoo.com/mrss/")]
public partial class MediaContent
{
[XmlAttribute(AttributeName = "url", Namespace = "http://search.yahoo.com/mrss/")]
public string url { get; set; }
[XmlAttribute(AttributeName = "type", Namespace = "http://search.yahoo.com/mrss/")]
public string type { get; set; }
[XmlAttribute(AttributeName = "medium", Namespace = "http://search.yahoo.com/mrss/")]
public string medium { get; set; }
}
[XmlType("description", Namespace = "http://search.yahoo.com/mrss/")]
public partial class MediaDescription
{
[XmlAttribute("type", Namespace="http://search.yahoo.com/mrss/")]
public string type {get;set;}
[XmlText]
public string description { get; set; }
}
#endregion
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 用于 Google 数据 API 的 .NET 库。另外,这里有一个您可能会感兴趣的教程:创建您的第一个 Picasa Web C#应用程序。
Your solution could be dramatically simplified making use of the .NET library for the Google Data API. Plus here is a tutorial that you might find interesting: Creating your first Picasa Web C# Application.