private void ParseDoc()
        {
            XmlDocument xmlDoc;
             XmlNode rootNode;

             try
             {
                 //remove <!DOCTYPE tv SYSTEM "xmltv.dtd"> string, 'cause xmldocument doesn't support it
                 m_Content = m_Content.Remove(44, 32);

                 //load content into xmldoc
                 xmlDoc = new XmlDocument();
                 xmlDoc.LoadXml(m_Content);

                 foreach (XmlNode commNode in xmlDoc.SelectNodes("//comment()"))
                 {
                     commNode.ParentNode.RemoveChild(commNode);
                 }

                 rootNode = xmlDoc.DocumentElement;

                 if ((rootNode == null) ||!rootNode.Name.Equals("tv"))
                 {
                     throw new Exception("TV tag not found. XML file not well formed.");
                 }

                 if (!rootNode.FirstChild.Name.Equals("programme"))
                 {
                    throw new Exception("programme tag not found. XML file not well formed.");
                 }

                 //enough of the checking, let's parse the file already!

                 //create an holder collection for our programmes
                 ProgrammeCollection progColl = new ProgrammeCollection();

                 foreach (XmlNode programmeNodes in rootNode.SelectNodes("programme"))
                 {
                     //define defaults
                     string _title = "unknown title";
                     string _lang = "unknown lang";
                     string _descr = "no description";
                     string _date ="unknown date";
                     string _type ="unknown type";
                     string _channel = "unknown channel";

                     XmlNode nodTitle = programmeNodes.SelectSingleNode("title");
                     XmlNode nodDesc = programmeNodes.SelectSingleNode("desc");
                     XmlNode nodDate = programmeNodes.SelectSingleNode("date");

                     XmlNodeList nodCategories = programmeNodes.SelectNodes("category");
                     if (nodCategories.Count > 0)
                     {
                         foreach (XmlNode nodCategory in nodCategories)
                         {
                             _type += nodCategory.InnerText + ",";
                         }

                     }
                     if (nodTitle != null)
                     {
                         _title = nodTitle.InnerText;
                     }

                     if (nodDesc != null)
                     {
                         _descr = nodDesc.InnerText;
                     }

                     if (nodDate != null)
                     {
                         _date = nodDate.InnerText;
                     }

                     //get parameters
                     _channel = programmeNodes.Attributes.GetNamedItem("channel").Value;
                     DateTime _startTime = ConvertTime(programmeNodes.Attributes.GetNamedItem("start").Value);
                     DateTime _stopTime = ConvertTime(programmeNodes.Attributes.GetNamedItem("stop").Value);
                     _lang = programmeNodes.SelectSingleNode("title").Attributes.GetNamedItem("lang").Value;

                     //create an programme object with above parameters
                     Programme progXML = new Programme(_channel,
                                                        _date,
                                                        _type,
                                                        _title,
                                                        _lang,
                                                        _startTime,
                                                        _stopTime,
                                                        _descr);

                     progColl.Add(progXML);

                 }

                 parsedProgs = progColl;
             }
             catch (XmlException ex)
             {

                 throw new Exception("Error parsing XML file. Msg: " + ex.Message);
             }
        }
示例#2
0
 public void Remove(Programme oChannel)
 {
     List.Remove(oChannel);
 }
示例#3
0
 public void Insert(int index, Programme oChannel)
 {
     List.Insert(index, oChannel);
 }
示例#4
0
 public int IndexOf(Programme oChannel)
 {
     return List.IndexOf(oChannel);
 }
示例#5
0
 public bool Contains(Programme oChannel)
 {
     return List.Contains(oChannel);
 }
示例#6
0
 public int Add(Programme oChannel)
 {
     return List.Add(oChannel);
 }