public void WriteToXml()
{
string file = Server.MapPath("/pages/iosqingqiuneirong.xml");
if (File.Exists(file))
{
XmlDocument xml = new XmlDocument();
xml.Load(file);
XmlNodeList node = xml.SelectNodes("books/book");
int count = Convert.ToInt32(node.Item(node.Count - 1).ChildNodes.Item(0).InnerText);
count++;
XmlElement ab = xml.CreateElement("book");
StringBuilder s = new StringBuilder();
s.Append("<count>" + count + "</count>");
s.Append("<date>" + DateTime.Now + "</date>");
s.Append("<content>" + HttpContext.Current.Request.Url.ToString() + "</content>");
ab.InnerXml = s.ToString();
xml.DocumentElement.AppendChild(ab);
xml.Save(file);
}
else
{
Response.Write("文件不存在");
}
在iis 中发布之后 可能会报错 无法写入xml 中
这个是需要设置xml的安全 权限问题 ;
中文写入 xml 会出现乱码的问题:
需要对中文转码
或者把 xml的编码方式 由默认的uft-8 改为 gb2312