示例#1
0
        /// <summary>
        /// 结构转换成XML
        /// </summary>
        /// <param name="playlist">播放列表</param>
        /// <returns></returns>
        public string ToXml(AMS_PlayListMd5Model playlist)
        {
            //TODO:转换成xml结构的算法
            //创建一个xml对象
            XmlDocument xmlDoc = new XmlDocument();
            //创建开头
            XmlDeclaration dec = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);

            xmlDoc.AppendChild(dec);
            //创建根节点
            XmlElement root = xmlDoc.CreateElement("Root");

            root.SetAttribute("Num", playlist.PlayListNo);
            root.SetAttribute("EffectDate", playlist.EffectDate.ToShortDateString());
            root.SetAttribute("EndDate", playlist.EndDate.ToShortDateString());
            root.SetAttribute("PlayElapsed", playlist.PlayElapsed.ToString());
            //创建二级节点
            XmlElement SecNode = xmlDoc.CreateElement("VideoItems");

            root.AppendChild(SecNode);
            //遍历媒体文件并添加到节点中
            foreach (AMS_VideoMd5Item video in playlist.PlayVideoItems)
            {
                XmlElement ThirdNode = xmlDoc.CreateElement("Video");
                ThirdNode.SetAttribute("name", video.Name);
                ThirdNode.SetAttribute("playtime", video.PlayTime);
                ThirdNode.SetAttribute("source", video.RelativeUrl);
                ThirdNode.SetAttribute("md5value", video.md5value);

                SecNode.AppendChild(ThirdNode);
                //不重复的视频文件名称
                int i;
                for (i = 0; i < VideoFiles.Count; i++)
                {
                    if (VideoFiles[i].Name == video.Name)
                    {
                        break;
                    }
                }
                if (i >= VideoFiles.Count)
                {
                    VideoFiles.Add(video);
                }
            }
            //在根节点中添加二级节点
            root.AppendChild(SecNode);
            //添加根节点
            xmlDoc.AppendChild(root);
            return(xmlDoc.OuterXml);
        }
示例#2
0
 public void AddFile(ISingleFile file)
 {
     VideoFiles.Add(file);
     Videos.Add(file.VideoFileName);
 }