问个关于System.xml的问题?(pie9912)

pie9912 2001-10-23 10:59:54
我想通过C#来实现往我的xml文件中加入数据!
我的infor.xml
<person>
<name>pie</name>
<E_mail>pie@263.com</E_mail>
<address>xmu</address>
</person>
怎么加入一个节点为<person>
请高手帮忙!
谢谢!
...全文
70 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhang_samuel 2001-10-24
  • 打赏
  • 举报
回复
if following is your infor.xml ( suppose it located in root directory of disk C)
<?xml version="1.0" encoding="utf-8"?>
<Root>
<person>
<name>pie</name>
<E_mail>pie@263.com</E_mail>
<address>xmu</address>
</person>
</Root>

XmlDocument doc;
doc=new XmlDocument();
doc.Load(@"c:\Infor.XML");

XmlElement rootElement=doc.DocumentElement;

XmlElement newChild;
XmlElement newChild2;
XmlElement newChild3;
XmlElement newChild4;

newChild= doc.CreateElement("person");

// <person>
//<name>pie</name>
//<E_mail>pie@263.com</E_mail>
//<address>xmu</address>
//</person>
newChild2=doc.CreateElement("name");
newChild2.InnerText="pie";
newChild3=doc.CreateElement("E_mail");
newChild3.InnerText="pie@263.com";
newChild4=doc.CreateElement("address");
newChild4.InnerText="xmu";
newChild.AppendChild(newChild2);
newChild.AppendChild(newChild3);
newChild.AppendChild(newChild4);

rootElement.AppendChild(newChild);
doc.Save(@"c:\Infor.XML");
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using InfoSoftGlobal; using System.Text; using System.Data.SqlClient; using System.Data; namespace MYASP { /// /// Author:jilongliang /// public partial class index : System.Web.UI.Page { protected void Page_Load (object sender, EventArgs e) { } /// /// 直接在控件加载出来 /// /// /// protected void Literal1_Load (object sender, EventArgs e) { Literal1.Text = FusionCharts.RenderChart("swf/ScrollCombiDY2D.swf", "fusioncharts.xml", "", "fusioncharts1", "500", "500", false, true); } /// /// 用户输入显示的图形fusioncharts /// /// /// protected void btnSubmit_Click (object sender, EventArgs e) { //Request.Form() //Label1.Text = Request["ponit1"]; StringBuilder xmlData = new StringBuilder(); xmlData.Append(""); xmlData.AppendFormat("", txtPoint1.Text); //txtPoint1.Text xmlData.AppendFormat("", txtPoint2.Text); xmlData.AppendFormat("", txtPoint3.Text); xmlData.AppendFormat("", txtPoint4.Text); xmlData.Append(""); Literal1.Text = FusionCharts.RenderChart("swf/Pie3D.swf", "", xmlData.ToString(), "fusioncharts2", "800", "500", false, false); } /// /// 从数据库读数据 /// /// /// protected void Literal2_Load (object sender, EventArgs e) { string query = "select Team ,Points from tb_charts"; StringBuilder xmlData = new StringBuilder(); using(SqlDataReader dr = SQLDBHelper.ExecuteReader(CommandType.Text, query, null)) { // xmlData.AppendFormat(""); while(dr.Read()) { xmlData.AppendFormat("", dr ["Team"].ToString(), dr ["Points"].ToString()); } xmlData.AppendFormat(""); Literal2.Text = FusionCharts.RenderChart("swf/Column3D.swf", "", xmlData.ToString(), "testChart", "500", "500", false, true); } } /// /// /// /// /// protected void test2_Click (object sender, EventArgs e) { string str1=Request ["ponit1"]; Label1.Text=str1; StringBuilder xmlData = new StringBuilder(); xmlData.Append(""); xmlData.AppendFormat("", txtPoint1.Text); //txtPoint1.Text xmlData.AppendFormat("", txtPoint2.Text); xmlData.AppendFormat("", txtPoint3.Text); xmlData.AppendFormat("", txtPoint4.Text); xmlData.Append(""); Literal1.Text = FusionCharts.RenderChart("swf/Pie3D.swf", "", xmlData.ToString(), "fusioncharts2", "800", "500", false, false); } protected void test2_Click1 (object sender, EventArgs e) { } } }

111,115

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧