XmlDocument xmlDoc = new XmlDocument();
xmlDoc.PreserveWhitespace = true;
xmlDoc.Load(Server.MapPath("xmlfile.xml"));
// return xmlDoc.InnerXml;
txtHtml.Text = xmlDoc.InnerXml;
Sys.xml
<?xml version="1.0" encoding="utf-8" ?>
<Settings>
<ConsumeMoney>300</ConsumeMoney>
</Settings>
///读
public string GetValue()
{
XmlDocument xDoc = new XmlDocument();
//获取可执行文件的路径和名称
xDoc.Load("Sys.xml");
XmlNode xNode;
XmlElement xElem1;
xNode = xDoc.SelectSingleNode("Settings");
xElem1 = (XmlElement)xNode.SelectSingleNode("ConsumeMoney");
if (xElem1 != null)
return xElem1.InnerText;
else
return "";
}
//写
public void SetValue(string AppKey, string AppValue)
{
XmlDocument xDoc = new XmlDocument();
//获取可执行文件的路径和名称
xDoc.Load("Sys.xml");
XmlNode xNode;
XmlElement xElem1;
XmlElement xElem2;
xNode = xDoc.SelectSingleNode("Settings");
xElem1 = (XmlElement)xNode.SelectSingleNode(AppKey);
if (xElem1 != null)
xElem1.InnerText = AppValue;
else
{
xElem2 = xDoc.CreateElement(AppKey);
xElem2.Value = AppValue;
xNode.AppendChild(xElem2);
}
xDoc.Save("Sys.xml");
}