c#: Deserializing xml with namespaces to clr object -
i need xmlserializer. have following xml fragment:
<?xml version='1.0' encoding='utf-8'?> <?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?> <feed xmlns='http://www.w3.org/2005/atom' xmlns:opensearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'> <id>tag:blogger.com,1999:blog-4233645339430781865.archive</id> <updated>2012-10-22t07:00:02.139+03:00</updated> <title type='text'>code !t</title> <link rel='alternate' type='text/html' href='http://www.etabakov.com/'/> <author> <name>Емил Табаков</name> <email>noreply@blogger.com</email> <gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-tbrwl19g85u/aaaaaaaaaai/aaaaaaaafxg/nrv6zyqd9wg/s512-c/photo.jpg'/> </author> <generator version='7.00' uri='http://www.blogger.com'>blogger</generator> <entry> <id>tag:blogger.com,1999:blog-4233645339430781865.post-513753811167440871</id> <published>2012-10-12t11:22:35.759+03:00</published> <updated>2012-10-12t11:22:35.759+03:00</updated> <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/blogger/2008/kind#comment'/> <title type='text'>great post indeed. prov...</title> <content type='html'>great post indeed. providing information on .net freshers , being enrolled @ http://www.wiziq.com/course/57-fresher-training-projects found information helpful indeed. it.</content> <link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4233645339430781865/8317071019326278340/comments/default/513753811167440871'/> <author> <name>sarabjeet</name> <uri>http://www.blogger.com/profile/11223974173581186160</uri> <email>noreply@blogger.com</email> <gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/> </author> <thr:in-reply-to href='http://www.etabakov.com/2012/06/net-guy-velocityconf-2012-day-1.html' ref='tag:blogger.com,1999:blog-4233645339430781865.post-8317071019326278340' source='http://www.blogger.com/feeds/4233645339430781865/posts/default/8317071019326278340' type='text/html'/> <gd:extendedproperty name='blogger.itemclass' value='pid-899300522'/> </entry> </feed>
and have following c# objects:
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> 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<category> 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; } }
everything works far, except replyto property stays null. need src attribute
i happy if show me i'm missing. thanks!
the namespace need "http://purl.org/syndication/thread/1.0"
"thr" alias - declared xmlns:thr
@ top.
so:
[xmlelement(elementname = "in-reply-to", namespace = "http://purl.org/syndication/thread/1.0", type = typeof(replyto), isnullable = true)] public replyto replyto { get; set; }
Comments
Post a Comment