62,074
社区成员
发帖
与我相关
我的任务
分享
//这是c#
public void insertxml(string xmlpath, string root, string node1, string node1value, string node2, string node2value)
{
try
{
FileStream xmlfilein;
xmlfilein = new FileStream(xmlpath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
DataSet ds = new DataSet();
ds.ReadXml(xmlfilein);
xmlfilein.Close();
//写入xml文件
DataRow newrow = ds.Tables[root].NewRow();
newrow[node1] = node1value;
newrow[node2] = node2value;
ds.Tables[root].Rows.Add(newrow);
FileStream xmlfileout;
xmlfileout = new FileStream(xmlpath, FileMode.Open, FileAccess.Write, FileShare.ReadWrite);
ds.WriteXml(xmlfileout, XmlWriteMode.WriteSchema);
xmlfileout.Close();
}
catch (Exception)
{
sundries.Show_Msg("填加XML数据错误,可能没有足够权限.");
}
private string writeXML(HttpContext context)
{
string H_shopcom = context.Request.Form.Get("shopcom");
string H_text = context.Request.Form.Get("text");
string xmlpath = context.Server.MapPath("message5.xml");
insertxml(xmlpath, "item", "title", "aa", "text", H_text );
return "aaaa";
}