[转]操作xml,将xml数据显示到treeview的C#代码
XmlDocument xml = new XmlDocument();
private void Form1_Load(object sender, EventArgs e)
{
CreateXML();
TreeNode tn = new TreeNode("魔兽");
treeView1.Nodes.Add(tn);
xml.Load(@"D:\XMLFile.xml");
XmlNode nod = xml.DocumentElement;
int i = ;
foreach (XmlNode xn in nod.ChildNodes)
{
treeView1.TopNode.Nodes.Add(xn.Attributes["two"].Value);
foreach (XmlNode xn2 in xn.ChildNodes)
{
treeView1.TopNode.Nodes[i].Nodes.Add(xn2.InnerText);
}
i++;
}
}
public void CreateXML()
{
//创建xml文件
XmlDeclaration dec = xml.CreateXmlDeclaration("1.0", "utf-8", null);
xml.AppendChild(dec);
//添加树形字段
XmlElement one = xml.CreateElement("one");
XmlElement two = xml.CreateElement("two");
XmlElement two1 = xml.CreateElement("two");
XmlElement three = xml.CreateElement("three");
XmlElement threeDL = xml.CreateElement("three");
XmlElement three1 = xml.CreateElement("three");
XmlElement three10 = xml.CreateElement("three");
//添加树形结构关系
xml.AppendChild(one);
one.AppendChild(two);
one.AppendChild(two1);
two.AppendChild(three);
two.AppendChild(threeDL);
two1.AppendChild(three1);
two1.AppendChild(three10);
//添加属性
two.SetAttribute("two", "不死");
two1.SetAttribute("two", "暗夜");
//添加内容
three.InnerText = "DK";
threeDL.InnerText = "DL";
three1.InnerText = "DH";
three10.InnerText = "WD";
xml.Save(@"D:\XMLFile.xml");
}

转:http://www.jb51.net/article/43892.htm
[转]操作xml,将xml数据显示到treeview的C#代码的更多相关文章
- asp.net mvc后台操作之读写xml控制首页动态页面开关显示
一.背景 在asp.net mvc项目里,用户需要开拓几个活动版面,并以侧栏的方式呈现在首页右侧,几个活动时间不一致,为避免浏览者在活动未开放之时进入未开放的服务页面.因此不仅需要在活动代码中加入限制 ...
- XML Helper XML操作类
写的一个XML操作类,包括读取/插入/修改/删除. using System;using System.Data;using System.Configuration;using System.Web ...
- 通过pull解析器操作安卓的xml
通过pull解析器操作安卓的xml 例子定义了一个javabean用于存放上面解析出来的xml内容, 这个javabean为Person,代码请见本页下面备注: =================== ...
- c# 文件操作 txt、xml、ini
1. txt文件 /// <summary> /// 读文本文件信息 /// </summary> /// <param name="FilePath" ...
- Xml学习笔记(3)利用递归解析Xml文档添加到TreeView中
利用递归解析Xml文档添加到TreeView中 private void Form1_Load(object sender, EventArgs e) { XmlDocument doc = new ...
- c# 操作临时数据---XML操作
class Config { static string path; /// <summary> /// 配置文件的路径 /// </summary> public stati ...
- Querying Microsoft SQL Server 2012 读书笔记:查询和管理XML数据 1 -使用FOR XML返回XML结果集
XML 介绍 <CustomersOrders> <Customer custid="1" companyname="Customer NRZBB&qu ...
- hadoop三个配置文件的参数含义说明core-site.xml,hdfs-site.xml,mapred-site.xml
配置hadoop,主要是配置core-site.xml,hdfs-site.xml,mapred-site.xml三个配置文件,默认下来,这些配置文件都是空的,所以很难知道这些配置文件有哪些配置可以生 ...
- 【XML】 XML格式一些记录
XML XML格式常用于网络通讯,本身不会有作为而是作为纯文本传输,可以说它是一种独立于应用和硬件的数据传输工具.虽然看起来XML比HTML要更加简单,也知道的更加晚一点,但是需要知道的是,XML才是 ...
随机推荐
- 基于TCP协议的服务器(单线程)
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import ...
- 《Linear Algebra and Its Applications》-chaper1-线性方程组- 线性变换
两个定理非常的简单显然,似乎是在证明矩阵代数中的基本运算律.但是它为后面用“线性变换”理解矩阵-向量积Ax奠定了理论基础. 结合之前我们讨论过的矩阵和向量的积Ax的性质,下面我们就可以引入线性变换了. ...
- The File's Owner
The File Owner is an instantiated, runtime object that owns the contents of your nib and its outlets ...
- NTP DDOS攻击
客户端系统会ping到NTP服务器来发起时间请求更换,同步通常每隔10分钟发生: 从NTP服务器发回到客户端的数据包可能比初始请求大几百倍.相比之下,通常用于放大攻击中的DNS响应被限制仅为8倍的带宽 ...
- UVA 10047 The Monocycle (状态记录广搜)
Problem A: The Monocycle A monocycle is a cycle that runs on one wheel and the one we will be consi ...
- RestService中的 get post put delete
HTTP 定义了与服务器交互的不同方法,最基本的有四种方法:GET,POST,PUT,DELETE.URL即资源描述符,我们可以这样认为:一个URL地址, 用于描述一个网络上的资源,而HTTP中的GE ...
- Ajax页面跳转
<script type="text/javascript" > $(document).ready(function () { $(&qu ...
- ASP.NET MVC- VIEW Using the TagBuilder Class to Build HTML Helpers Part 3
The ASP.NET MVC framework includes a useful utility class named the TagBuilder class that you can u ...
- shell查找文件并删除
-mtime 0 表示文件改动时间距离当前为0天的文件.即距离当前时间不到1天(24小时)以内的文件. -mtime 1 表示文件改动时间距离当前为1天的文件,即距离当前时间1天(24小时-48小时) ...
- RichtextBox 行和列
获得光标所在的行号 获得光标所在的列号 设置光标到指定行号 设置光标到指定列号 http://www.huifangseo.com/blog/6/7.html 获得光标所在的行号和列号 方法1 int ...