c# - Data at the root level is invalid RSS feed with web api and wpf xmldataprovider -
i'm trying set rss feed using syndicate feed object homecoming wpf application uses xmldataprovider. maintain getting
data @ root level invalid>
here's current code rss feed. shows fine in browser xml.
[route("test")] public rss20feedformatter get() { var feed = new syndicationfeed("test feed", "this test feed", new uri("http://google.com")); feed.categories.add(new syndicationcategory("test")); feed.description = new textsyndicationcontent("this test feed see how easy is"); var test = new syndicationitem("blah.blah@test.com", "this note", new uri("http://google.com"), "blah.blah@test.com", datetime.now); test.categories.add(new syndicationcategory("person")); test.authors.add(new syndicationperson("test@test.com")); var items = new list<syndicationitem> {test}; feed.items = items; homecoming new rss20feedformatter(feed, false); }
and xaml code:
<window x:class="rssreader.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="mainwindow" height="350" width="525"> <window.resources> <xmldataprovider source="http://localhost:8080/api/test/" x:key="xdata" xpath="//item"></xmldataprovider> </window.resources> <grid> <listbox itemssource="{binding source={staticresource xdata}}"> </listbox> </grid>
i've tried microsoft feeds: http://www.microsoft.com/en-us/news/rss/rssfeed.aspx?contenttype=pressreleases , works mine error
edit here's xml returned api
<rss version="2.0"> <channel> <title>test feed</title> <link>http://google.com/</link> <description>this test feed see how easy is</description> <category>test</category> <item> <guid ispermalink="false">blah.blah@test.com</guid> <link>http://google.com/</link> <author>test@test.com</author> <category>person</category> <title>blah.blah@test.com</title> <description>this note</description> </item> </channel> </rss>
so turns out rss20feedformatter doesn't set xml tags @ top of rss stream, dataprovider fails read it.
instead, going write formatter xmlwriter , add together tags in way
edit i've added code below how achieved. bit of mess around utf encoding correct.
[route("test")] public httpresponsemessage get() { var feed = new syndicationfeed("test feed", "this test feed", new uri("http://google.com")); feed.categories.add(new syndicationcategory("test")); feed.description = new textsyndicationcontent("this test feed see how easy is"); var test = new syndicationitem("blah.blah@test.com", "this note", new uri("http://google.com"), "blah.blah@test.com", datetime.now); test.categories.add(new syndicationcategory("person")); test.authors.add(new syndicationperson("blah@blah.com")); var test2 = new syndicationitem("blah.blah@test2.com", "this note", new uri("http://google.com"), "blah.blah@test2.com", datetime.now); test2.categories.add(new syndicationcategory("person")); test2.authors.add(new syndicationperson("blah@blah.com")); var items = new list<syndicationitem> { test, test2 }; feed.items = items; var formatter = new rss20feedformatter(feed); var output = new memorystream(); var xws = new xmlwritersettings {encoding = encoding.utf8}; using (var xmlwriter = xmlwriter.create(output, xws)) { formatter.writeto(xmlwriter); xmlwriter.flush(); } string xml; using (var sr = new streamreader(output)) { output.position = 0; xml = sr.readtoend(); sr.close(); } var response = new httpresponsemessage(httpstatuscode.ok) { content = new stringcontent(xml, encoding.utf8, "application/xml")}; homecoming response; }
c# wpf xaml rss web-api
No comments:
Post a Comment