. Net two methods for reading rss

Source: Internet
Author: User

1. Use DataSet to obtain the data.
There is a ReadXml method in DataSet. This method has the following overload

Public XmlReadMode ReadXml (stringfileName)

The fileName parameter must provide the address of an xml file. It can be a relative path, an absolute path, or a URL address,
For example

DataTable tbl = new DataSet (). ReadXml ("http://inan.cn/feed.asp"). Table ["item"];

All content of the item node in rss is returned.
As for the field, you can traverse the Column of the DataTable.
Of course, the above Code is just a rough code and does not handle any exceptions. For example, there will be exceptions in ReadXml and exceptions in Table fetch.
With DataTable, the rest is much easier.

2. Use XmlDocument for processing.

XmlDocument doc = new XmlDocument ();
Doc. Load ("http://inan.cn/feed.asp"); // Load an xml document into XmlDocument
XmlNodeList nodelist = doc. GetElementsByTagName ("item"); // obtain all item items
Foreach (XmlNode node in nodelist ){
Foreach (XmlNode childnode in node. ChildNodes ){
Response. Write (childnode. Name + "=" + childnode. InnerText + "<br/> ");
}
}

You can also use the DataSet. ReadXml and XmlDocument. Load methods to perform other overload operations.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.