c#:使用命名空间将xml反序列化为clr对象

我需要一些XmlSerializer的帮助。 我必须遵循xml片段:

   tag:blogger.com,1999:blog-4233645339430781865.archive 2012-10-22T07:00:02.139+03:00 Code !t   Емил Табаков noreply@blogger.com   Blogger  tag:blogger.com,1999:blog-4233645339430781865.post-513753811167440871 2012-10-12T11:22:35.759+03:00 2012-10-12T11:22:35.759+03:00  Great post indeed. I really like that you are prov... Great post indeed. I really like that you are providing information on .NET for freshers , Being enrolled at http://www.wiziq.com/course/57-fresher-training-projects i found your information very helpful indeed. Thanks for it.   sarabjeet http://www.blogger.com/profile/11223974173581186160 noreply@blogger.com       

我还有以下c#对象:

Feed.cs

 [XmlRoot(ElementName = "feed", Namespace = "http://www.w3.org/2005/Atom"), XmlType("feed")] public class Feed { [XmlElement("id")] public string Id { get; set; } [XmlElement("title")] public string Title { get; set; } [XmlElement("author")] public Author Author { get; set; } [XmlElement("entry")] public List Entry; } public class Entry { [XmlElement("id")] public string Id { get; set; } [XmlElement("title")] public string Title { get; set; } [XmlElement("content")] public string Content { get; set; } [XmlElement("published")] public DateTime Published { get; set; } [XmlElement("updated")] public DateTime Updated { get; set; } [XmlElement("category")] public List Categories; [XmlElement("author")] public Author Author { get; set; } [XmlElement(ElementName = "in-reply-to", Namespace = "thr", Type = typeof(ReplyTo), IsNullable = true)] public ReplyTo ReplyTo { get; set; } } public class ReplyTo { [XmlAttribute("ref")] public string Id { get; set; } } 

到目前为止,一切都运行良好,除了ReplyTo属性始终保持为null。 我需要从中获取src属性

如果有人告诉我我缺少的东西,我会很高兴的。 谢谢!

您需要的命名空间是“http://purl.org/syndication/thread/1.0”

“thr”只是别名 – 由xmlns:thr在顶部声明。

所以:

 [XmlElement(ElementName = "in-reply-to", Namespace = "http://purl.org/syndication/thread/1.0", Type = typeof(ReplyTo), IsNullable = true)] public ReplyTo ReplyTo { get; set; }