/// <summary> /// 描述: /// 加载播放列表 /// </summary> private void LoadPlaylist() { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(_strXmlFilePath); // 加载XML文件 XmlNodeList nodeList = xmlDoc.SelectSingleNode("PlayList").SelectNodes("List"); lvPlaylist.Items.Clear(); // 清空播放列表 foreach (XmlNode list in nodeList) { ListViewItem lvItemName = new ListViewItem(); string fileName = list.SelectSingleNode("FileName").InnerText; lvItemName.Content = fileName as object; PlayListItems[fileName] = list.SelectSingleNode("FilePath").InnerText; lvPlaylist.Items.Add(lvItemName); } }
/// <summary> /// 描述: /// 将指定的文件写入到XML文件中的Playlist中 /// </summary> private void WriteToXML(string strFilePath, string strFileName) { //首先创建 XmlDocument xml文档 XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(_strXmlFilePath); //新建一个节点 List(用于做子节点) XmlElement list = xmlDoc.CreateElement("List"); xmlDoc.SelectSingleNode("PlayList").AppendChild(list); // 创建FilePath子节点 XmlElement filePath = xmlDoc.CreateElement("FilePath"); filePath.InnerText = strFilePath; list.AppendChild(filePath); // 创建FileName子节点 XmlElement fileName = xmlDoc.CreateElement("FileName"); fileName.InnerText = strFileName; list.AppendChild(fileName); //最后将整个xml文件保存 xmlDoc.Save(_strXmlFilePath); }
时间: 2024-10-28 10:12:25