private void SaveRss()
{
try
{
// 创建XmlTextWriter类的实例对象
// string sfile=;
//string str = "rss version="+2.0;
FileInfo file = new FileInfo(Server.MapPath("rss.xml"));
if (!file.Exists){
XmlTextWriter textWriter = new XmlTextWriter(Server.MapPath("rss.xml"), System.Text.Encoding.UTF8);
// 开始写过程,调用WriteStartDocument方法 写入文件头信息 例如<?xml version="1.0" encoding="utf-8"?>
textWriter.WriteStartDocument();
//写入根节点<phonebook></phoebook>
textWriter.WriteStartElement("rss");
textWriter.WriteStartElement("channel");
// 写入节点title
textWriter.WriteStartElement("title", "");
textWriter.WriteString("中国藏医药热线");
textWriter.WriteEndElement();
// 写入节点link
textWriter.WriteStartElement("link", "");
textWriter.WriteString("http://www.cacaos.net");
textWriter.WriteEndElement();
// 写入节点description
textWriter.WriteStartElement("description", "");
textWriter.WriteString("中国藏医药热线,藏医药知识咨询,产品订购服务!");
textWriter.WriteEndElement();
// 写入节点pubDate
textWriter.WriteStartElement("pubDate", "");
textWriter.WriteString(DateTime.Now.ToString());
textWriter.WriteEndElement();
// 写入节点item
textWriter.WriteStartElement("item");
// 写入节点title
textWriter.WriteStartElement("title", "");
textWriter.WriteString("中国藏医药热线");
textWriter.WriteEndElement();
// 写入节点link
textWriter.WriteStartElement("link", "");
textWriter.WriteString("http://www.cacaos.net");
textWriter.WriteEndElement();
// 写入节点description
textWriter.WriteStartElement("description", "");
textWriter.WriteString("中国藏医药热线,藏医药知识咨询,产品订购服务!");
textWriter.WriteEndElement();
// 写入节点pubDate
textWriter.WriteStartElement("pubDate", "");
textWriter.WriteString(DateTime.Now.ToString());
textWriter.WriteEndElement();
// 写入节点author
textWriter.WriteStartElement("author", "");
textWriter.WriteString("何永");
textWriter.WriteEndElement();
//写入item节点的结束符
textWriter.WriteEndElement();
// 写文档结束,调用WriteEndDocument方法
textWriter.WriteEndDocument();
// 关闭textWriter
textWriter.Close();
}
else
{
SaveXMLData_nodemode();
}
// 显示所有用户的留言信息
//Response.Redirect("viewphonebook_reader.aspx");
}
catch {
ClientScript.RegisterStartupScript(typeof(string),"","<script language='javascript'>alert('dsf');</script>");
}
#region 生成RSS(用node方式写入XML)
private void SaveXMLData_nodemode()
{
try
{
// 创建一个XmlDocument对象,用于载入存储信息的XML文件
XmlDocument xdoc = new XmlDocument();
xdoc.Load(Server.MapPath("rss.xml"));
// 创建一个新的menber节点并将它添加到根节点下
XmlElement parentNode = xdoc.CreateElement("member");
xdoc.DocumentElement.PrependChild(parentNode);
// 创建所有用于存储信息的节点
XmlElement nameNode = xdoc.CreateElement("name");
XmlElement telphoneNode = xdoc.CreateElement("telphone");
XmlElement qqNode = xdoc.CreateElement("qq");
XmlElement msnNode = xdoc.CreateElement("msn");
XmlElement cellphoneNode = xdoc.CreateElement("cellphone");
XmlElement workNode = xdoc.CreateElement("work");
XmlElement addressNode = xdoc.CreateElement("address");
XmlElement emailNode = xdoc.CreateElement("email");
/* 获取文本信息
XmlText nameText = xdoc.CreateTextNode(Request.Form.Get("name"));
XmlText telphoneText = xdoc.CreateTextNode(Request.Form.Get("telphone"));
XmlText qqText = xdoc.CreateTextNode(Request.Form.Get("qq"));
XmlText msnText = xdoc.CreateTextNode(Request.Form.Get("msn"));
XmlText cellphoneText = xdoc.CreateTextNode(Request.Form.Get("cellphone"));
XmlText workText = xdoc.CreateTextNode(Request.Form.Get("work"));
XmlText addressText = xdoc.CreateTextNode(Request.Form.Get("address"));
XmlText emailText = xdoc.CreateTextNode(Request.Form.Get("email")); */
// 获取文本信息
XmlText nameText = xdoc.CreateTextNode("name");
XmlText telphoneText = xdoc.CreateTextNode("telphone");
XmlText qqText = xdoc.CreateTextNode("qq");
XmlText msnText = xdoc.CreateTextNode("msn");
XmlText cellphoneText = xdoc.CreateTextNode("cellphone");
XmlText workText = xdoc.CreateTextNode("work");
XmlText addressText = xdoc.CreateTextNode("address");
XmlText emailText = xdoc.CreateTextNode("email");
// 将上面创建的各个存储信息的节点添加到menber节点下但并不包含最终的值
parentNode.AppendChild(nameNode);
parentNode.AppendChild(telphoneNode);
parentNode.AppendChild(qqNode);
parentNode.AppendChild(msnNode);
parentNode.AppendChild(cellphoneNode);
parentNode.AppendChild(workNode);
parentNode.AppendChild(addressNode);
parentNode.AppendChild(emailNode);
// 将上面获取的文本信息添加到与之相对应的节点中
nameNode.AppendChild(nameText);
telphoneNode.AppendChild(telphoneText);
qqNode.AppendChild(qqText);
msnNode.AppendChild(msnText);
cellphoneNode.AppendChild(cellphoneText);
workNode.AppendChild(workText);
addressNode.AppendChild(addressText);
emailNode.AppendChild(emailText);
// 保存存储信息的XML文件
xdoc.Save(Server.MapPath("rss.xml"));
// 显示所有用户的留言信息
Response.Redirect("viewphonebook_reader.aspx");
}
catch (Exception se) { Console.WriteLine(se.Message); }
}
#endregion
}
/***************************************************************/
#region 意见调查
protected void Button1_Click(object sender, EventArgs e)
{
//load xml file
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("vode.xml"));
string vOne = RadioButtonList1.SelectedItem.Text;
string vSen = RadioButtonList2.SelectedItem.Text;
XmlNodeList nodeLis = xmlDoc.SelectSingleNode("root/vode").ChildNodes;
try
{
if (vOne == "赞成")
nodeLis[0].InnerText = (Convert.ToInt32(nodeLis[0].InnerText) + 1).ToString();
else
nodeLis[1].InnerText = (Convert.ToInt32(nodeLis[1].InnerText) + 1).ToString();
if (vSen == "亲切")
nodeLis[2].InnerText = (Convert.ToInt32(nodeLis[2].InnerText) + 1).ToString();
else if (vSen == "严肃")
nodeLis[3].InnerText = (Convert.ToInt32(nodeLis[3].InnerText) + 1).ToString();
else
nodeLis[4].InnerText = (Convert.ToInt32(nodeLis[4].InnerText) + 1).ToString();
}
catch { }
finally
{
xmlDoc.Save(Server.MapPath("vode.xml"));
ClientScript.RegisterStartupScript(typeof(string), "jyu", "<script language='javascript'>alert('谢谢你的宝贵意见!');</script>");
}
}
#endregion