62,046
社区成员
发帖
与我相关
我的任务
分享
public DataSet ReadXml()
{
DataSet ds = new DataSet();
ds.ReadXml("ControlConfig.xml");
return ds;
}
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.HttpContext.Current.Server.MapPath;
using System.Xml;
/// <summary>
/// Summary description for ControlXml
/// </summary>
public class ControlXml
{
public ControlXml()
{
//
// TODO: Add constructor logic here
//
}
public void WriteXml(string controlMsg, string controlType, string controlID)
{
//初始化XML文档操作类
XmlDocument myXml = new XmlDocument();
//加载指定的XML文件
myXml.Load("ControlConfig.xml");
//添加元素-姓名
XmlElement ele0 = myXml.CreateElement("controlType");
XmlText Text0 = myXml.CreateTextNode(controlType);
XmlElement ele1 = myXml.CreateElement("controlMsg");
XmlText Text1 = myXml.CreateTextNode(controlMsg);
XmlElement ele2 = myXml.CreateElement("controlID");
XmlText Text2 = myXml.CreateTextNode(controlID);
//添加元素的节点---studentRecord
XmlNode newElem = myXml.CreateNode("element","Controls", "");
//在节点中添加元素
newElem.AppendChild(ele0);
newElem.LastChild.AppendChild(Text0);
newElem.AppendChild(ele1);
newElem.LastChild.AppendChild(Text1);
newElem.AppendChild(ele2);
newElem.LastChild.AppendChild(Text2);
//将节点添加到文档中
XmlElement root = myXml.DocumentElement;
root.AppendChild(newElem);
//保存所有的修改
myXml.Save("ControlConfig.xml");
}
public DataSet ReadXml()
{
DataSet ds = new DataSet();
//ds.ReadXml(Server.Mappath("ControlConfig.xml"));
string path = System.Web.HttpContext.Current.Server.MapPath("./") + "ControlConfig.xml";
ds.ReadXml(path);
return ds;
}
public void DelXml()
{
XmlDocument myXml = new XmlDocument();
//加载指定的XML文件
myXml.Load("ControlConfig.xml");
//myXml.RemoveChild();
}
}