RSS reader make the TreeView data export to XML data publication date: 2006-11-30

Source: Internet
Author: User
Tags date return string version
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 ("&LT;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;
}
}
}



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.