数据库如何设计,及要生成下面这种格式类型的xml文件(可能是无限级的)
<?xml version="1.0" encoding="gb2312"?>
<Employees>
<Node genre="李赞红" ISBN="2-3631-4">
<title>
<first>中国 </first>
<second>编程 <second>
</title>
<author>候捷 </author>
<price>58.3 </price>
</Node>
</employees>
<?xml version="1.0" encoding="gb2312"?>
<Employees>
<Node genre="李赞红" ISBN="2-3631-4">
<title>
<first>中国 </first>
<second>编程 <second>
</title>
<author>候捷 </author>
<price>58.3 </price>
</Node>
</employees>
<Node genre="李赞红" ISBN="2-3631-4">
<title>
<first>中国 </first>
<second>编程 <second>
</title>
<author>候捷 </author>
<price>58.3 </price>
</Node>
表里面的字段。。就OK了
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;namespace xmlDom
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button5_Click(object sender, EventArgs e)
{
XmlDocument xmlDoc = new XmlDocument();
XmlDeclaration xmldec = xmlDoc.CreateXmlDeclaration("1.0","gb2312",null);
xmlDoc.AppendChild(xmldec); XmlElement root = xmlDoc.CreateElement("书籍");
xmlDoc.AppendChild(root); XmlElement name = (XmlElement)xmlDoc.CreateElement("书名");
name.InnerText = "ASP高级编程";
root.AppendChild(name); XmlElement author = (XmlElement)xmlDoc.CreateElement("作者");
root.AppendChild(author); XmlElement xm = xmlDoc.CreateElement("姓名");
xm.InnerText = "爱因斯坦";
xm.SetAttribute("性别","男");
author.AppendChild(xm); XmlElement price = xmlDoc.CreateElement("价格");
price.InnerText = "63.50元";
root.AppendChild(price); XmlElement com = xmlDoc.CreateElement("出版社");
com.InnerText = "清华出版社";
root.AppendChild(com); XmlElement time = xmlDoc.CreateElement("发行日期");
time.InnerText = "2009年3月10号";
root.AppendChild(time); xmlDoc.Save("book.xml");
} private void button1_Click(object sender, EventArgs e)//增加节点
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("book.xml"); XmlNode root = xmlDoc.SelectSingleNode("书籍");
XmlElement xxx = xmlDoc.CreateElement("营养");
xxx.InnerText = "100%";
root.AppendChild(xxx); xmlDoc.Save("book.xml");
} private void button2_Click(object sender, EventArgs e)//删除某节点
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("book.xml"); XmlNode root = xmlDoc.SelectSingleNode("书籍");
XmlNode xxx = root.SelectSingleNode("营养");
root.RemoveChild(xxx);
xmlDoc.Save("book.xml");
}
private void button3_Click(object sender, EventArgs e)//修改某节点
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("book.xml"); XmlNode name = xmlDoc.SelectSingleNode("书籍/作者");
(name as XmlElement).SetAttribute("性别","女");
name.InnerText = "乖乖";
xmlDoc.Save("book.xml");
}
private void button4_Click(object sender, EventArgs e)//查询某节点
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("book.xml"); XmlNode name = xmlDoc.SelectSingleNode("书籍/书名"); xmlDoc.Save("book.xml");
}
}
}实现XML的增删改查