Linq to XML reads the RSS article list code in one sentence

  • 2020-05-10 17:57:50
  • OfStack

Just write this in the Page_Load() method on the page:

new XDocument( 
new XElement("ol", 
from item in XDocument.Load("http://cnblogs.com/rss").Descendants("item") 
select new XElement[]{ 
new XElement("li", 
new XElement("a",(string)item.Element("title"), 
new XAttribute("href",(string)item.Element("link")) 
) 
) 
} 
) 
).WriteTo(new XmlTextWriter(Response.OutputStream,Encoding.UTF8));

Related articles: