惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
Help Net Security
Help Net Security
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
C
Cisco Blogs
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
L
LINUX DO - 热门话题
Security Latest
Security Latest
A
Arctic Wolf
G
GRAHAM CLULEY
月光博客
月光博客
S
Securelist
D
Docker
J
Java Code Geeks
T
Troy Hunt's Blog
T
Tenable Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
SecWiki News
SecWiki News
S
Security @ Cisco Blogs
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
LINUX DO - 最新话题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
aimingoo的专栏
aimingoo的专栏
博客园 - 【当耐特】
H
Heimdal Security Blog
The Hacker News
The Hacker News
博客园 - 三生石上(FineUI控件)
Application and Cybersecurity Blog
Application and Cybersecurity Blog
N
Netflix TechBlog - Medium
Vercel News
Vercel News
Forbes - Security
Forbes - Security
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
B
Blog
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
S
Secure Thoughts
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Check Point Blog
云风的 BLOG
云风的 BLOG
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Blog of Author Tim Ferriss
L
Lohrmann on Cybersecurity
F
Full Disclosure
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Proofpoint News Feed

博客园 - Toney

[转]IT从业人员必看的10个论坛 国内.NET论坛源代码搜集 Ajax学习网址收集 Crystal Report Download URL and SN 学习计划 清辅音与浊辅音的区别 ASP.NET中实现URL重写 Asp.Net Form事件处理过程?? 建立职场B计划 世界五百强面试题目及应答评点10 各路由器的默认密码列表 .Text引用第三方组(控)件明细^_^ Debug和Release的区别 Visual Studio 2005 Express October 2004 CTP完整版本的下载 从 SQL Server 2005 中处理 XML ASP.NET 中的正则表达式 数据库应用:无法更新到数据库 如何构建积木式Web应用(引自微软CSDN ) Configuring IIS: Mapping .* to the aspnet_isapi.dll
递归遍历XML生成树
Toney · 2004-11-20 · via 博客园 - Toney

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
public partial class Default_aspx
{
 void Page_Load(object sender, EventArgs e)
 {

  string xmlstr = "<?xml version=\"1.0\"?><root><Note NodeName=\"的1\"><Note NodeName=\"的2\"><Note NodeName=\"的3\" /><Note NodeName=\"的4\" /></Note><Note NodeName=\"的5\" /></Note><Note NodeName=\"的6\"><Note NodeName=\"的7\"><Note NodeName=\"的8\" /><Note NodeName=\"的9\" /></Note><Note NodeName=\"的10\" /></Note></root>";
  IterateXml(xmlstr);
 }
/*
 <?xml version=\"1.0\"?><root><Note NodeName=\"的1\"><Note NodeName=\"的2\"><Note NodeName=\"的3\" /><Note NodeName=\"的4\" /></Note><Note NodeName=\"的5\" /></Note><Note NodeName=\"的6\"><Note NodeName=\"的7\"><Note NodeName=\"的8\" /><Note NodeName=\"的9\" /></Note><Note NodeName=\"的10\" /></Note></root>"
 */
 private void IterateXml(string xmlstr)
 {
  XmlDocument xmldoc = new XmlDocument();

  xmldoc.LoadXml(xmlstr);
  XmlNode worknode;
  TreeNode rootnode;
  for (int i = 0; i < xmldoc.DocumentElement.ChildNodes.Count; i++)
  {
   worknode = xmldoc.DocumentElement.ChildNodes[i];
   if (worknode.ChildNodes.Count > 0)
    rootnode = IterateChild(worknode);
   else
    rootnode = new TreeNode(worknode.Name);
   this.TreeView1.Nodes.Add(rootnode);   
  }
 }
 private TreeNode  IterateChild(XmlNode rootnode)
 {
  XmlNode worknode = rootnode;//当前遍历的节点

  System.Web.UI.WebControls.TreeNode retnode = new TreeNode(worknode.Attributes["NodeName"].Value); ;//要返回的树节点
  TreeNode newch;//中间树节点

  if (worknode.ChildNodes.Count < 1)
  {//没有子节点,生成一个树节点返回
   newch = new TreeNode(worknode.Attributes["NodeName"].Value);
   retnode = newch;
  }
  else //有子节点,调用递归
  {
   for (int i = 0; i < worknode.ChildNodes.Count; i++)
   {
    retnode.ChildNodes.Add(IterateChild(worknode.ChildNodes[i]));
   }
  }

  return retnode;
 }
}