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.