xml文档绑定某个属性值到treeview算法
原文发布时间为:2008-08-10 —— 来源于本人的百度文章 [由搬家工具导入]
using System.Xml;
protected void Button2_Click(object sender, EventArgs e)
{
string xmlpath = Server.MapPath("~/App_Data/dirList.xml");
if (File.Exists(xmlpath))
{
XmlDocument dom = new XmlDocument();
dom.Load(xmlpath);
TreeView1.Nodes.Clear();
BindXmlToTreeView(dom.DocumentElement.ChildNodes, TreeView1.Nodes);
}
else
{
Response.Write("<script>alert('XML文档不存在,请先创建')</script>");
}
}
protected void BindXmlToTreeView(XmlNodeList xmlnodes, TreeNodeCollection treeNodes)
{
foreach (XmlNode child in xmlnodes)
{
if (child.Attributes != null && child.Attributes.Count > 0)//这个判断很重要!
{
string treeText = child.Attributes["name"].Value;
TreeNode tn = new TreeNode(treeText);
treeNodes.Add(tn);
BindXmlToTreeView(child.ChildNodes, tn.ChildNodes);
}
}
}
-----------------------------------------
原算法:
private void populateTreeControl( System.Xml.XmlNode document, System.Windows.Forms.TreeNodeCollection nodes)
{
foreach (System.Xml.XmlNode node in document.ChildNodes)
{ // If the element has a value, display it;
// otherwise display the first attribute
// (if there is one) or the element name
// (if there isn't)
string text = (node.Value != null ? node.Value : (node.Attributes != null && node.Attributes.Count > 0) ? node.Attributes[0].Value : node.Name);
TreeNode new_child = new TreeNode(text);
nodes.Add(new_child);
populateTreeControl(node, new_child.Nodes);
}
}
xml文档绑定某个属性值到treeview算法的更多相关文章
- 使用JAXP对XML文档进行DOM解析
import java.io.FileOutputStream; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers. ...
- XMLHelper类 源码(XML文档帮助类,静态方法,实现对XML文档的创建,及节点和属性的增、删、改、查)
以下是代码: using System; using System.Collections.Generic; using System.Linq; using System.Web; using Sy ...
- XML文档操作集锦(C#篇)
在JSON没流行起来的时候xml一直作为程序存储配置信息的主流介质:特别是小型数据表方面还是不错的选择,所以经常涉及到的操作无非也就是增删改查,这篇博客主要是对这些对比较常用的操作做了个简单的总结 文 ...
- 根据Attribute值条件对XML文档进行修改
现手上有一个XML文档, 需要把"直接工序"改为"间接工序0". 你可以使用<对XML文档进行修改> http://www.cnblogs.com/ ...
- 用Castor 处理XML文档
——Castor可以完成Java和XML的相互转换 前面有介绍过json-lib这个框架,在线博文:http://www.cnblogs.com/hoojo/archive/2011/04/21/20 ...
- XML文档中的xmlns、xmlns:xsi和xsi:schemaLocation
文章转载自:https://yq.aliyun.com/articles/40353 相信很多人和我一样,在编写Spring或者Maven或者其他需要用到XML文档的程序时,通常都是将这些XML文档头 ...
- 关于XML文档的xmlns、xmlns:xsi和xsi:schemaLocation
https://yq.aliyun.com/articles/40353 ************************************* 摘要: 相信很多人和我一样,在编写Spring或者 ...
- Spring学习----- Spring配置文件xml文档的schema约束
1.配置文件示例. <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="htt ...
- 关于Spring配置文件xml文档的schema约束
最开始使用spring框架的时候,对于其配置文件xml,只是网上得知其使用方法,而不明其意.最近想着寻根问底的探究一下.以下是本文主要内容: 1.配置文件示例. <?xml version=&q ...
随机推荐
- 01_1_准备ibatis环境
01_1_准备ibatis环境 1. 搭建环境:导入相关的jar包 mysql-connector-java-5.1.5-bin.jar(mysql)或者ojdbc6.jar(oracle).ibat ...
- ssh整合思想 Spring分模块开发 crud参数传递 解决HTTP Status 500 - Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or(增加事务)
在Spring核心配置文件中没有增加事务方法,导致以上问题 Action类UserAction package com.swift.action; import com.opensymphony.xw ...
- attachEvent和addEventListener 的使用方法和区别
attachEvent方法,为某一事件附加其它的处理事件.(不支持Mozilla系列)addEventListener方法 用于 Mozilla系列document.getElementById(&q ...
- 洛谷 P5015 标题统计
第一道题很简单,标签:字符串.模拟. 只需要一个判断去除空格就对了: if(a[i]!=' ' && a[i]!='\n') v++; code: #include<iostre ...
- paper:synthesizable finite state machine design techniques using the new systemverilog 3.0 enhancements 之 FSM Coding Goals
1.the fsm coding style should be easily modifiable to change state encoding and FSM styles. FSM 的的 状 ...
- 7.Yii2.0框架自定义全局工具函数
功能: 新建共用方法的打印方法,可以很方便的格式化打印 一.新建helper/function.php <?php /** * Created by Haima. * Author:Haima ...
- 《linux设备驱动开发详解》笔记——12linux设备驱动的软件架构思想
本章重点讲解思想.思想.思想. 12.1 linux驱动的软件架构 下述三种思想,在linux的spi.iic.usb等复杂驱动里广泛使用.后面几节分别对这些思想进行详细说明. 思想1:驱动与设备分离 ...
- Solr 7 部署与使用踩坑全记录
前言 Solr 是一种可供企业使用的.基于 Lucene 的搜索服务器,它支持层面搜索.命中醒目显示和多种输出格式.在这篇文章中,我将介绍 Solr 的部署和使用的基本操作,希望能让初次使用的朋友们少 ...
- 博客笔记(blog notebook)
1. 机器学习 2. NLP 3. code 实际好人 实际坏人 预测百分比 预测好人 \(p_GF^c(s_c\|G)\) \(p_BF^c(s_c\|B)\) \(F^c(s_c)\) 预测坏人 ...
- Numpy ndarray 的高级索引存在 "bug" ?
Numpy ndarray 高级索引 "bug" ? 话说一天,搞事情,代码如下 import numpy as np tmp = [1, 2, 3, 4] * 2 a, b = ...