您的位置:首页 > 其它

XML删除按钮,修改并保存按钮 和 添加按钮。完成这些按钮所对应的功能(XmlDocument)。

2012-12-21 23:50 357 查看
protected void Button3_Click(object sender, EventArgs e)

{

XmlElement bo = xdoc.CreateElement("book");

XmlElement au = xdoc.CreateElement("author");

XmlElement pu = xdoc.CreateElement("publisher");

XmlElement na = xdoc.CreateElement("name");

XmlElement pr = xdoc.CreateElement("price");

XmlElement isb = xdoc.CreateElement("isbn");

XmlElement da = xdoc.CreateElement("date");

xdoc.AppendChild(au);

xdoc.AppendChild(bo);

xdoc.AppendChild(pu);

xdoc.AppendChild(na);

xdoc.AppendChild(pr);

xdoc.AppendChild(isb);

xdoc.AppendChild(da);

xdoc.Save(Server.MapPath("newbook2.xml"));

this.ClientScript.RegisterClientScriptBlock(this.GetType(),"kk","<script type='text/javascript'>alter</script>");

}

protected void Button2_Click(object sender, EventArgs e)

{

XmlNode node = xdoc.DocumentElement.SelectSingleNode("book[name='" + this.DropDownList1.Text + "']");

node.SelectSingleNode("author").InnerText = this.TextBox1.Text;

node.SelectSingleNode("publisher").InnerText = this.TextBox2.Text;

node.SelectSingleNode("date").InnerText = this.TextBox3.Text;

node.SelectSingleNode("isbn").InnerText = this.TextBox4.Text;

node.SelectSingleNode("price").InnerText = this.TextBox5.Text;

xdoc.Save(Server.MapPath("books.xml"));

// Page.RegisterClientScriptBlock("key1","<script type='text/javascript'>alter</script >");

this.ClientScript.RegisterClientScriptBlock(this.GetType(),"key2","<script type='text/javascript'>alter</script >");

}

protected void Button4_Click(object sender, EventArgs e)

{

XmlNode node = xdoc.DocumentElement.SelectSingleNode("book[name='"+this.DropDownList1.Text+"']");

xdoc.DocumentElement.RemoveChild(node);

this.DropDownList1.Items.RemoveAt(this.DropDownList1.SelectedIndex);

xdoc.Save(Server.MapPath("newbook.xml"));

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐