怎么用XML做数据库c#
来源:互联网 发布:大数据系统 安全防护 编辑:程序博客网 时间:2024/04/29 05:29
xml实际就是一个本地简单的数据库
我只做了一个简单的。。但是道理是一样的。
//xml文件信息
<abc>
<Field>100</Field>
<item>
<id>1</id>
<name>zhangsan</name>
<sex>男</sex>
</item>
<item>
<id>2</id>
<name>lisi</name>
<sex>男</sex>
</item>
</abc>
//实体类。
public class Information
{
private string id;
public string Id
{
get { return id; }
set { id = value; }
}
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private string sex;
public string Sex
{
get { return sex; }
set { sex = value; }
}
public Information()
{
}
public Information(string id,string name,string sex)
{
this.Id = id;
this.Name = name;
this.Sex = sex;
}
}
//读取xml里面的文件信息
List<Information> list = new List<Information>();
//实例化xml
XmlDocument xml = new XmlDocument();
//读取xml文件
xml.Load(@"E:\C#\S2C#\DLCL\打印电脑\MyComputer\XulieHua\XML.xml"); //你的xml地址
string id = "";
string name = "";
string sex = "";
Information info = null;
//////////*******下面开始循环读取xml文件信息********/
///////////////
foreach (XmlNode node in xml.ChildNodes)
{
if (node.Name == "abc")
{
foreach (XmlNode node1 in node.ChildNodes)
{
if (node1.Name == "item")
{
foreach (XmlNode node2 in node1.ChildNodes)
{
switch (node2.Name)
{
case "id":
id = node2.InnerText;
break;
case "name":
name = node2.InnerText;
break;
default:
sex = node2.InnerText;
break;
}
}
info = new Information(id, name, sex);
//将信息保存至集合
list.Add(info);
}
}
}
}
xml里面的所有信息就是在list集合里面了。。简单吧。。嘿嘿。。
当然你可以做多个表和多个字段属性咯。。
我只做了一个简单的。。但是道理是一样的。
//xml文件信息
<abc>
<Field>100</Field>
<item>
<id>1</id>
<name>zhangsan</name>
<sex>男</sex>
</item>
<item>
<id>2</id>
<name>lisi</name>
<sex>男</sex>
</item>
</abc>
//实体类。
public class Information
{
private string id;
public string Id
{
get { return id; }
set { id = value; }
}
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private string sex;
public string Sex
{
get { return sex; }
set { sex = value; }
}
public Information()
{
}
public Information(string id,string name,string sex)
{
this.Id = id;
this.Name = name;
this.Sex = sex;
}
}
//读取xml里面的文件信息
List<Information> list = new List<Information>();
//实例化xml
XmlDocument xml = new XmlDocument();
//读取xml文件
xml.Load(@"E:\C#\S2C#\DLCL\打印电脑\MyComputer\XulieHua\XML.xml"); //你的xml地址
string id = "";
string name = "";
string sex = "";
Information info = null;
//////////*******下面开始循环读取xml文件信息********/
///////////////
foreach (XmlNode node in xml.ChildNodes)
{
if (node.Name == "abc")
{
foreach (XmlNode node1 in node.ChildNodes)
{
if (node1.Name == "item")
{
foreach (XmlNode node2 in node1.ChildNodes)
{
switch (node2.Name)
{
case "id":
id = node2.InnerText;
break;
case "name":
name = node2.InnerText;
break;
default:
sex = node2.InnerText;
break;
}
}
info = new Information(id, name, sex);
//将信息保存至集合
list.Add(info);
}
}
}
}
xml里面的所有信息就是在list集合里面了。。简单吧。。嘿嘿。。
当然你可以做多个表和多个字段属性咯。。
- 怎么用XML做数据库c#
- 怎么用XML做数据库c#
- C#怎么复制窗体/C#窗体复用怎么做
- Winform怎么复制窗体/C#窗体复用怎么做
- C#中怎么去用XML实例
- XML 做小型数据库
- C#拿怎么做Codereview?
- 怎么做mysql数据库索引
- 怎么做mysql数据库索引
- 用TXT 做数据库怎么保证TXT文件的安全
- 怎么做网站XML地图讲解
- XML做数据库 知识总结
- C#怎么连接SQL数据库.
- C#怎么连接Oracle数据库
- C# 图片防盗链怎么做
- c# 数据库 操做大全
- oracle 数据库忘记密码怎么做
- 数据库三表连接查询怎么做
- toggle()-显示隐藏控件
- fedora 14安装qt4开发环境
- Web 网站开发
- 关于web.xml配置的详细说明
- 取得cxGrid 合计数
- 怎么用XML做数据库c#
- cvc-complex-type.2.4.a: Invalid content was found starting with element 'taglib'错误
- 经常DML操作对索引的影响
- 使用JAXP进行DOM解析( DocumentBuilderFactory、DocumentBuilder、Document)
- 号段提取工具
- error C2787: “LogLevel”: 没有与该对象关联的 GUID
- 修改WAMP中mysql默认空密码
- Hibernate一对一关联(共享主键) 注解 || xml
- Advanced SQL Server Monitor with Performance Graph, Analysis and Version Control