日期:2014-05-17 浏览次数:20949 次
/// <summary>
/// 2、添加元素
/// </summary>
/// <param name="xmlpath">XML文件的路径</param>
private static void AddXmlElement(string xmlpath)
{
///导入XML文件
XElement xe = XElement.Load(xmlpath);
///创建一个新节点
XElement book1 = new XElement("Book",
new XAttribute("BookID", "002"),
new XElement("BookNo", "0002"),
new XElement("BookName", "Book 0002"),
new XElement("BookPrice", "50"),
new XElement("BookRemark", "This is a book 0002")
);
///添加节点到XML文件中,并保存
xe.Add(book1);
///创建一个新节点
XElement book2 = new XElement("Book",
new XAttribute("BookID", "003"),
new XElement("BookNo", "0003"),
new XElement("BookName", "Book 0003"),
new XElement(