日期:2014-04-07 浏览次数:21001 次
//递归遍历节点内容,最关键的函数 private void parseNode(TreeNode tn) { IEnumerator ie = tn.Nodes.GetEnumerator(); while (ie.MoveNext()) { TreeNode ctn = (TreeNode) ie.Current; //为最底层节点,即该节点为RSS节点 if (ctn.GetNodeCount(true) == 0) { xmlLine = GetRSSText(ctn); sr.WriteLine(xmlLine); }
/**//*-------------------------------------------------------------
* 作者:刘晓松
* 版本:1.0.0
* 日期:2006.10.29
* 描述:将TreeView中导出为XML数据
-------------------------------------------------------------*/
using System;
using System.Collections;
using System.IO;
using System.Windows.Forms;
namespace TreeViewExport
...{
/**//// <summary>
/// 将TreeView中导出为XML数据
/// </summary>
public class TreeViewToXmlB
...{
//XML每行的内容
private string xmlLine = "";
//用于写XML文件
private StreamWriter sr;
/**//// <summary>
/// 结构函数
/// </summary>
public TreeViewToXmlB()
...{
}
/**//// <summary>
/// 将TreeView中导出为XML数据
/// </summary>
/// <param name="tv">TreeView控件</param>
/// <param name="filename">XML文件的保存路径</param>
public void exportToXml(TreeView tv, string filename)
...{
sr = new StreamWriter(filename, false, System.Text.Encoding.UTF8);
//写文件头部内容
//下面是生成RSS的OPML文件
sr.WriteLine("<?xml version="1.0" encoding="UTF-8"?>");
sr.WriteLine("<opml version="1.0">");
sr.WriteLine("<head>");
sr.WriteLine("<title>RSS</title>");
sr.WriteLine("</head>");
sr.WriteLine("<body>");
//遍历根节点
foreach (TreeNode node in tv.Nodes)
...{
if (node.GetNodeCount(true) == 0)
...{
xmlLine = GetRSSText(node);
&nbs