- Home /
Convert XML/HTML from RSS feed into something usefull?
I'm building an Windows Universal App for a Raspberry Pi 2. I used the System.Data-library (DataSet) for interpretation of this kind of info:
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>TV 2 - alle nyheder</title>
<description>Nyheder fra tv2.dk</description>
<link>http://tv2.dk</link>
<lastBuildDate>Sun, 13 Sep 2015 14:30:23 GMT</lastBuildDate>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<image>
<title>TV 2 - alle nyheder</title>
<url>http://tv2.dk/profiles/tv2/modules/custom/t2zerowing/pkg/img/apple-touch-icon-precomposed.png</url>
<link>http://tv2.dk</link>
</image>
<copyright>Copyright © TV 2 DANMARK A/S. All rights reserved</copyright>
<generator>Feed for Node.js</generator>
<item>
<title><![CDATA[DF hiver Søren Pind i samråd om flygtningesituation]]></title>
<link>http://politik.tv2.dk/2015-09-13-df-hiver-soeren-pind-i-samraad-om-flygtningesituation</link>
<guid>http://politik.tv2.dk/node/68459</guid>
<pubDate>Sun, 13 Sep 2015 14:25:51 GMT</pubDate>
<description><![CDATA[<p><img src="http://drupal-images.tv2.dk/sites/images.tv2.dk/files/t2img/2015/09/13/960x540/168641983-20150618-220158-L.jpg" alt="" /></p><p>Dansk Folkeparti vil have justitsministeren til at redegøre for flygtningesituationen, som de kalder kaotisk.</p>
<p>Dansk Folkeparti kræver nu justitsminister Søren Pind (V) i samr&ar...</p>]]></description>
<content:encoded><![CDATA[-]]></content:encoded>
<author>
<name>Ritzau</name>
</author>
</item>
<item>
<title><![CDATA[TV 2 LIVECENTER: Tyskland vil indføre grænsekontrol]]></title>
<link>http://nyhederne.tv2.dk/2015-09-12-tv-2-livecenter-tyskland-vil-indfoere-graensekontrol</link>
<guid>http://drupal-nyhederne.tv2.dk/node/861893</guid>
<pubDate>Sun, 13 Sep 2015 14:24:57 GMT</pubDate>
<description><![CDATA[<p><img src="http://drupal-images.tv2.dk/sites/images.tv2.dk/files/t2img/2015/09/12/960x540/168197093-25658936-TV%202%20LIVECENTER.png.jpg" alt="" /></p><p>TV 2 Nyhederne giver dig dagens historier i TV 2 LIVECENTER.</p>
]]></description>
<content:encoded><![CDATA[-]]></content:encoded>
<author>
<name>Jakob Binderup</name>
</author>
</item>
But now that I'm targeting Universal App, I get lots of compile errors, because the assemblies I added myself (System.Data, and a few others) won't compile to Universal App, because they are not supported. Do any of you guys know a quick and handy way to somehow convert this XML/HTML kinda info into strings? NOTICE: In the "description" attribute is BOTH located the URL for the image, AND the main text, which I would like to get separated
Rasmus
I found that i can use System.Xml. I'm trying to figure out how to extract "title" and "description" from each item (Look at the X$$anonymous$$L code snippet above). I'm trying this:
public void ReadX$$anonymous$$L(WWW www)
{
xmlDoc = new XmlDocument();
xmlDoc.LoadXml(www.text);
foreach (XmlElement node in xmlDoc.SelectNodes("Item"))
{
Debug.Log("I was called !!!!!!!!");
RSSItem rssItem = new RSSItem();
rssItem.title = node.SelectSingleNode("title").InnerText;
rssItem.description= node.SelectSingleNode("description").InnerText;
}
}
But i don't even enter the foreach-loop. Any of you guys know how to extract "title" and "description" ?
Answer by OJ3D · Jan 24, 2016 at 04:07 PM
Found the sleekest answer for Rss feeds (see the link below). The unity package is provided for free too.
http://forum.unity3d.com/threads/rss-reading-into-unity-example.61332/
I made several attempts at the deserialization efforts and it would only partially come through. I have a feel it had something to do with the RSS element as a XLMroot or something like that. Anyway, the package above is still relevant and easily modifiable. Also, make sure you're URL to your xml file doesn't have a "https" but make sure it's "http". For some reason it didn't place nicely with the security protocol version.
OJ
Answer by j0ffe · Sep 13, 2015 at 03:42 PM
Their is a lot of XML serialize out their.
This one for example: http://www.codeproject.com/Articles/34045/Yet-Another-XML-Serialization-Library-for-the-NET
Which one is best for your work is probably only you that knows.
Search for C# XML library and you will get tons of results.
Your answer
Follow this Question
Related Questions
c# convert int to string 2 Answers
Converting String to a Game Object 1 Answer
html links in strings or GUI components possible? 1 Answer
Parseing Varible names from strings 1 Answer
Simple XML reading? (only string/numerical data needed) 1 Answer