Posted on 10/7/2008 10:39:03 PM by Justin Etheredge
I have actually had several e-mails over the last few months which requested that I put out a list of all the blogs that I subscribe to. I use Google Reader so I just exported my list to OPML (Outline Processor Markup Language) and then I needed to get it into an HTML list so that I could display it in my blog. So I decided to write a little Linq To XML program to take in the OPML file and spit out an HTML unordered list. Below I am going to list all of the blogs I follow, and then link to the OPML file. Then below that I am going to show you the code that I used to transform the OPML file.
Here is a list of the blogs that I frequent...
And here is the OPML file.
Here is the short snippet of C# that transforms the OPML into an HTML list:
var sr = new StreamReader("Opml.xml");
XDocument doc = XDocument.Load(new XmlTextReader(sr));
var result =
new XElement("ul",
from c in doc.Elements("opml").Elements("body").Elements("outline")
select
new XElement("li",
new XElement("a",
new XAttribute("href", c.Attribute("htmlUrl").Value),
c.Attribute("text").Value
),
" ",
new XElement("a",
new XAttribute("href", c.Attribute("xmlUrl").Value),
"RSS"
)
)
);
using (var xtw = new XmlTextWriter(new StreamWriter("list.xml")))
{
xtw.Formatting = Formatting.Indented;
result.WriteTo(xtw);
}
If you see this, and feel inspired, publish your own blog list and let me know! Also, if you see that I am missing any really good blogs, please leave me a comment and let me know! I hope that this helps someone out!
Comments