Let’s take a look at the effect first:
First, an ascx page is needed to bind the content of the rss source to a ListView through an XDocument. The code is as follows:
protected void Page_Load(object sender, EventArgs e )
{
// For demo purposes.
System.Threading.Thread.Sleep(1000);
XDocument feedXML =
XDocument.Load("http://feeds .feedsky.com/csdn.net/dujingjing1230");
var feeds = from feed in feedXML.Descendants("item")
select new
{
Title = feed.Element ("title").Value,
Link = feed.Element("link").Value,
Description = feed.Element("description").Value
};
PostList.DataSource = feeds;
PostList.DataBind();
}
<%# Eval("Title") %>
<%# Eval( "Description") %>
Next you need to create an aspx page to Display RSS content. Of course, this page uses jQuery's AJAX to get the above data.
HTML page code:
JS to implement ajax function:
$(document).ready(function() {
$.ajax({
type: "POST",
url: "RSSReader.asmx/GetRSSReader" ,
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
$('#RSSContent').removeClass('loading');
$('#RSSContent').html(msg.d);
}
});
});
Finally is the content of the web service RSSReader.asmx:
public class RSSReader : System.Web.Services.WebService {
[WebMethod]
public string GetRSSReader()
{
Page page = new Page();
UserControl ctl =
(UserControl)page.LoadControl("~/RSSReaderControl.ascx");
page.Controls.Add(ctl);
StringWriter writer = new StringWriter();
HttpContext .Current.Server.Execute(page, writer, false);
return writer.ToString();
}
}
There is also an image used in the page, here it is No more uploading.
Code download:
http://xiazai.jb51.net/200909/yuanma/RSSREader.rarStatement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn