日期:2014-05-16 浏览次数:20517 次
protected void BtAdd_Click(object sender, EventArgs e)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("../admin/playlist.xml"));
XmlNode root = xmlDoc.SelectSingleNode("playlist");
XmlNode tracklist = root.FirstChild;//查找<trackList>
XmlElement xe1 = xmlDoc.CreateElement("track");//创建一个<track>节点
XmlElement title = xmlDoc.CreateElement("title");//设置歌曲节点
XmlElement location = xmlDoc.CreateElement("location");//设置链接节点
title.InnerText = TextName.Text.Trim();
location.InnerText = TextPath.Text.Trim();
xe1.AppendChild(title);//添加到<track>节点中
xe1.AppendChild(location);
tracklist.AppendChild(xe1);//添加到<trackList>节点中
xmlDoc.Save("playlist.xml");
Common.ShowMsgAndRedirect("歌曲插入成功", this.Page, "music.aspx");
}
<?xml version="1.0" encoding="UTF-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<trackList>
<track>
<location>/source/yqnyh.mp3</location>
<title>一千年以后</title>
</track>
</trackList>
</playlist>
XmlSerializer serializer = new XmlSerializer(typeof(playlist));
string xmlContent = File.ReadAllText("XMLFile1.xml");
using (TextReader reader = new StringReader(xmlContent))
{
playlist playList = serializer.Deserialize(reader) as playlist;
//modify existing track
if (playList.trackList.Count > 0)
playList.trackList[0].title = "modified title";
&nb