Xml-treeview conversion,

Source: Internet
Author: User

Xml-treeview conversion,
XML --> treeciew

Using System; using System. collections. generic; using System. text; using System. windows. forms; using System. xml; namespace TreeExXML {class TreeExXMLCls {private TreeView thetreeview; private string xmlfilepath; XmlDocument textdoc; public TreeExXMLCls () {// ---- constructor textdoc = new XmlDocument ();}~ TreeExXMLCls () {// ---- destructor} # region traverses XML and converts to tree /// <summary> // traverses treeview and converts to XML /// </ summary> /// <param name = "XMLFilePath"> XML output path </param> /// <param name = "TheTreeView"> tree control object </param> // /<returns> 0 indicates smooth function execution </returns> public int XMLToTree (string XMLFilePath, treeView TheTreeView) {// ------- re-initialize the Conversion Environment Variable thetreeview = TheTreeView; xmlfilepath = XMLFilePath; // ------- re-assign textdoc to the XMLDocument object. load (xmlfilepath); XmlNode root = textdoc. selectSingleNode ("Sinumerik"); TreeNode bootTreeNode = new TreeNode (); bootTreeNode. text = "Sinumerik"; thetreeview. nodes. add (bootTreeNode); foreach (XmlNode subXmlnod in root. childNodes) {// TreeNode trerotnod = new TreeNode (); TreeNode treeNode = new TreeNode (); XmlElement element = (XmlElement) subXmlnod; treeNode. text = element. getAttribute ("Title"); treeNode. toolTipText = element. getAttribute ("Description"); bootTreeNode. nodes. add (treeNode); // xml three-tier structure --- TransXML (subXmlnod. childNodes, treeNode);} return 0;} private int TransXML (XmlNodeList Xmlnodes, TreeNode partrenod) {// ------ traverse all nodes in XML, modeled after the treeview node traversal function foreach (XmlNode xmlnod in Xmlnodes) {TreeNode subtreeNode = new TreeNode (); XmlElement element = (XmlElement) xmlnod; subtreeNode. text = element. getAttribute ("Title"); subtreeNode. toolTipText = element. getAttribute ("Description"); subtreeNode. tag = element. getAttribute ("nodeClass"); partrenod. nodes. add (subtreeNode); if (xmlnod. childNodes. count> 0) {TransXML (xmlnod. childNodes, subtreeNode) ;}} return 0 ;}# endregion }}

 

 

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.