rss|treeview|xml| data
Recursive traversal of node content, the most critical function of private void Parsenode (TreeNode tn) {IEnumerator ie = tn. Nodes.getenumerator (); while (ie. MoveNext ()) {TreeNode ctn = (TreeNode) ie. Current; is the lowest-level node, which is the RSS node if (CTN). Getnodecount (true) = = 0) {xmlline = Getrsstext (CTN); Sr. WriteLine (Xmlline); }
/**//*-------------------------------------------------------------
* Author: Liu Xiaosong
* Version: 1.0.0
* Date: 2006.10.29
* Description: Export the TreeView as XML data
-------------------------------------------------------------*/
Using System;
Using System.Collections;
Using System.IO;
Using System.Windows.Forms;
Namespace Treeviewexport
... {
/**////<summary>
Export the TreeView as XML data
</summary>
public class TREEVIEWTOXMLB
... {
Content for each line of XML
private string xmlline = "";
For writing XML files
Private StreamWriter SR;
/**////<summary>
Constructors
</summary>
Public treeviewtoxmlb ()
... {
}
/**////<summary>
Export the TreeView as XML data
</summary>
<param name= "TV" >treeview control </param>
<param name= "filename" >xml File save path </param>
public void Exporttoxml (TreeView TV, string filename)
... {
sr = new StreamWriter (filename, false, System.Text.Encoding.UTF8);
Write File header content
The following is the OPML file that generates RSS
Sr. WriteLine ("<?xml version=" 1.0 "encoding=" UTF-8 "?>");
Sr. WriteLine ("<OPML version=" 1.0 ">");
Sr. WriteLine ("Sr. WriteLine ("<title>RSS</title>");
Sr. WriteLine ("Sr. WriteLine ("<body>");
Traversing the root node
foreach (TreeNode node in TV. Nodes)
... {
if (node. Getnodecount (true) = = 0)
... {
Xmlline = getrsstext (node);
}
Else
... {
Xmlline = getdirectorytext (node);
}
Sr. WriteLine (Xmlline);
Recursive traversal node
Parsenode (node);
}
Write file tail content
Sr. WriteLine ("</body>");
Sr. WriteLine ("</opml>");
Sr. Close ();
}
Recursive traversal of node content, the most critical function
private void Parsenode (TreeNode tn)
... {
IEnumerator ie = tn. Nodes.getenumerator ();
while (ie. MoveNext ())
... {
TreeNode ctn = (TreeNode) ie. Current;
is the bottommost node, that is, the node is an RSS node
if (ctn. Getnodecount (true) = = 0)
... {
Xmlline = Getrsstext (CTN);
Sr. WriteLine (Xmlline);
}
else//is not the bottommost node, that is, the node is a directory node
... {
Xmlline = Getdirectorytext (CTN);
Sr. WriteLine (Xmlline);
}
Continue traversal if there are child nodes
if (ctn. Getnodecount (True) > 0)
... {
Parsenode (CTN);
}
}
Sr. WriteLine ("</outline>");
}
Genetic the XML text line of the RSS node
private string Getrsstext (TreeNode node)
... {
Generate XML text from node property
String rsstext = "<outline type=" RSS "text=" + node. Text + "xmlurl=" URL "/>";
return rsstext;
}
Genetic the XML text line of the directory node
private string Getdirectorytext (TreeNode node)
... {
Generate XML text from node property
String directorytext = "<outline text=" + node. Text + ">";
return directorytext;
}
}
}