从XML中获取频道信息
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Xml; 6 7 namespace TVProject_6 8 { 9 public class ChannelManger 10 { 11 public ChannelManger() 12 { 13 Channel=new Dictionary<string,ChannelBase>(); 14 } 15 16 public Dictionary<string,ChannelBase> Channel { get; set; } 17 18 /// <summary> 19 /// 获取电台信息 20 /// </summary> 21 public void LoadChannels() 22 { 23 XmlDocument xmlDoc = new XmlDocument(); 24 xmlDoc.Load("FullChannels.xml"); 25 XmlNodeList fullChannelList = xmlDoc.GetElementsByTagName("Channel"); 26 foreach (XmlNode fullChannel in fullChannelList) 27 { 28 ChannelBase cb = ChannelFactory.GetChannel 29 (fullChannel["tvChannel"].InnerText, 30 fullChannel["path"].InnerText, 31 fullChannel["channelType"].InnerText); 32 33 Channel.Add(fullChannel["tvChannel"].InnerText, cb); 34 } 35 36 } 37 } 38 }
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace TVProject_6 7 { 8 /// <summary> 9 /// 频道基类 10 /// </summary> 11 public abstract class ChannelBase 12 { 13 public ChannelBase() 14 { 15 ProgramLis = new List<TVProgram>(); 16 } 17 18 public ChannelBase(string ChannelType) 19 { 20 ProgramLis = new List<TVProgram>(); 21 this.ChannelType = ChannelType; 22 } 23 24 /// <summary> 25 /// 频道类型 26 /// </summary> 27 public string ChannelType { get; set; } 28 29 /// <summary> 30 /// 频道名称 31 /// </summary> 32 public string TvChannel { get; set; } 33 34 /// <summary> 35 /// 频道路径 36 /// </summary> 37 public string Path { get; set; } 38 39 /// <summary> 40 /// 节目的集合 41 /// </summary> 42 public List<TVProgram> ProgramLis { get; set; } 43 44 /// <summary> 45 /// 46 /// </summary> 47 public abstract void LoadProgramList(); 48 49 } 50 }
1 <?xml version="1.0" encoding="utf-8" ?> 2 <TVChannels> 3 <Channel> 4 <channelType>TypeA</channelType> 5 <tvChannel>北京电视台</tvChannel> 6 <path>北京电视台.xml</path> 7 </Channel> 8 <Channel> 9 <channelType>TypeB</channelType> 10 <tvChannel>凤凰卫视</tvChannel> 11 <path>凤凰卫视.xml</path> 12 </Channel> 13 <Channel> 14 <channelType>TypeC</channelType> 15 <tvChannel>湖南卫视</tvChannel> 16 <path>湖南卫视.xml</path> 17 </Channel> 18 </TVChannels>
从XML文件中获取频道信息