vs2005 xml 添加
usingSystem.Xml;usingSystem.IO;publicpartialclassxmladd:System.Web.UI.Page{protectedv...
using System.Xml;
using System.IO;
public partial class xmladd : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
XmlDocument xmldoc;
XmlNode root, stuNode;
string stuName = tbStuName.Text;
string phone = tbPhone.Text;
string qq = tbQQ.Text;
string email = tbEmail.Text;
string home = tbHome.Text;
string headImage = fileHeadImage.PostedFile.FileName;
string[] filename=headImage.Split('\\');
headImage=filename[filename.Length-1];
fileHeadImage.PostedFile.SaveAs(Server.MapPath(".")+"/"+headImage);
string work = tbWork.Text; 展开
using System.IO;
public partial class xmladd : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
XmlDocument xmldoc;
XmlNode root, stuNode;
string stuName = tbStuName.Text;
string phone = tbPhone.Text;
string qq = tbQQ.Text;
string email = tbEmail.Text;
string home = tbHome.Text;
string headImage = fileHeadImage.PostedFile.FileName;
string[] filename=headImage.Split('\\');
headImage=filename[filename.Length-1];
fileHeadImage.PostedFile.SaveAs(Server.MapPath(".")+"/"+headImage);
string work = tbWork.Text; 展开
1个回答
展开全部
xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath("address.xml"));
root = xmldoc.DocumentElement;
XmlElement student = xmldoc.CreateElement("student");
XmlElement node1 = xmldoc.CreateElement("stuName");
node1.InnerText = stuName;
XmlElement node2 = xmldoc.CreateElement("phone");
node2.InnerText = phone;
XmlElement node3 = xmldoc.CreateElement("qq");
node3.InnerText = qq;
XmlElement node4 = xmldoc.CreateElement("email");
node4.InnerText = email;
XmlElement node5 = xmldoc.CreateElement("home");
node5.InnerText = home;
XmlElement node6 = xmldoc.CreateElement("headImage");
node6.InnerText = headImage;
XmlElement node7 = xmldoc.CreateElement("work");
node7.InnerText = work;
student.AppendChild(node1);
student.AppendChild(node2);
student.AppendChild(node3);
student.AppendChild(node4);
student.AppendChild(node5);
student.AppendChild(node6);
student.AppendChild(node7);
root.AppendChild(student);
xmldoc.Save(Server.MapPath("address.xml"));
}
xmldoc.Load(Server.MapPath("address.xml"));
root = xmldoc.DocumentElement;
XmlElement student = xmldoc.CreateElement("student");
XmlElement node1 = xmldoc.CreateElement("stuName");
node1.InnerText = stuName;
XmlElement node2 = xmldoc.CreateElement("phone");
node2.InnerText = phone;
XmlElement node3 = xmldoc.CreateElement("qq");
node3.InnerText = qq;
XmlElement node4 = xmldoc.CreateElement("email");
node4.InnerText = email;
XmlElement node5 = xmldoc.CreateElement("home");
node5.InnerText = home;
XmlElement node6 = xmldoc.CreateElement("headImage");
node6.InnerText = headImage;
XmlElement node7 = xmldoc.CreateElement("work");
node7.InnerText = work;
student.AppendChild(node1);
student.AppendChild(node2);
student.AppendChild(node3);
student.AppendChild(node4);
student.AppendChild(node5);
student.AppendChild(node6);
student.AppendChild(node7);
root.AppendChild(student);
xmldoc.Save(Server.MapPath("address.xml"));
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询