XML 读取修改操作。
读取
XmlTextReader
textReader =
new
XmlTextReader
(Server.MapPath(
"mb_Msg.xml"
));
textReader.Read();
while
(textReader.Read())
{
textReader.MoveToElement();
if
(textReader.Name ==
"msg"
)
{
content.Text = textReader.ReadString();
}
}
textReader.Close();
修改:
XmlDocument xml = new XmlDocument();
xml.Load(Server.MapPath("YG_msg.xml"));
XmlNode msg = xml.SelectSingleNode("/root/msg");
msg.InnerText = getstring(Request.Form["content"]);
XmlNode user = xml.SelectSingleNode("/root/user");
user.InnerText = getstring(Request.Form["fn_userName"]);
XmlNode pwd = xml.SelectSingleNode("/root/pwd");
if (getstring(Request.Form["fn_userPwd"]).Trim() != string.Empty)
{
pwd.InnerText = getstring(Request.Form["fn_userPwd"]);
}
xml.Save(Server.MapPath("YG_msg.xml"));
FormBase.showmsg("设置成功", "success", "", "closewin('winmsg');", this);
xml.Load(Server.MapPath("YG_msg.xml"));
XmlNode msg = xml.SelectSingleNode("/root/msg");
msg.InnerText = getstring(Request.Form["content"]);
XmlNode user = xml.SelectSingleNode("/root/user");
user.InnerText = getstring(Request.Form["fn_userName"]);
XmlNode pwd = xml.SelectSingleNode("/root/pwd");
if (getstring(Request.Form["fn_userPwd"]).Trim() != string.Empty)
{
pwd.InnerText = getstring(Request.Form["fn_userPwd"]);
}
xml.Save(Server.MapPath("YG_msg.xml"));
FormBase.showmsg("设置成功", "success", "", "closewin('winmsg');", this);
xml:(name='mb_Msg.xml')
<?
xml
version
=
"
1.0
"
encoding
=
"
utf-8
"
?>
<
root
>
<
msg
>
xm 您好,这是一条回访信息,请勿回复!
</
msg
>
</
root
>