/[xmltv_parser]/trunk/libxmltv/Core/XMLTVParser.cs
ViewVC logotype

Annotation of /trunk/libxmltv/Core/XMLTVParser.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (hide annotations) (download)
Thu Mar 7 11:08:48 2013 UTC (7 years, 7 months ago) by william
Original Path: trunk/libxmltv/Core/XMLTV_PARSER.cs
File size: 3388 byte(s)

1 william 23 #define XMLTV_PARSER_TESTING // when defined will allow calls to be made to _imp_TestParse()
2     using System;
3 william 22 using System.Collections.Generic;
4     using System.Linq;
5     using System.Text;
6     using libxmltv.Interfaces;
7 william 23 using System.Diagnostics;
8     using System.Xml.Linq;
9 william 22
10     namespace libxmltv.Core
11     {
12     internal class XMLTV_PARSER : IXMLTV_PARSER
13     {
14 william 23
15 william 22 public XMLTV_PARSER(object xmltv)
16     {
17     IXMLTV_LOADER _xmltv;
18     if (!Internals.VerifyInstance<IXMLTV_LOADER>(xmltv, out _xmltv)) { return; }
19     XMLTV_LOADER = _xmltv;
20     }
21     #region IXMLTV_PARSER members
22     public IXMLTV_LOADER XMLTV_LOADER { get; private set; }
23 william 23 public void TestParse() { _imp_TestParse(); }
24 william 22 #endregion
25 william 23
26     #region Parser Testing Methods
27     [Conditional("XMLTV_PARSER_TESTING")]
28     private void _imp_TestParse()
29     {
30     XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Running XML_PARSER Test");
31     var doc = XMLTV_LOADER.XmlDoc;
32     ParseRootElements(doc);
33     ParseChannels(doc);
34     ParsePrograms(doc);
35     }
36     [Conditional("XMLTV_PARSER_TESTING")]
37     private void ParseRootElements(XDocument doc)
38     {
39     XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Parseing Root Data");
40     Debug.Assert(doc.Root.Name == XMLTV_CONSTANTS.ROOT_ELEMENT, string.Format("Expected Root Element: '{0}' but read: '{1}'", XMLTV_CONSTANTS.ROOT_ELEMENT, doc.Root.Name));
41     XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tRoot: {0}", doc.Root.Name);
42     var attributes = doc.Root.Attributes().ToList();
43     foreach (var attribute in attributes)
44     {
45     XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t{0}: {1}", attribute.Name, attribute.Value);
46     }
47     }
48     [Conditional("XMLTV_PARSER_TESTING")]
49     private void ParseChannels(XDocument doc)
50     {
51     XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Parsing Channel Data");
52     var elements = doc.Root.Descendants(XMLTV_CONSTANTS.CHANNEL_ELEMENT).ToList();
53     foreach (var element in elements)
54     {
55     if (element.HasAttributes)
56     {
57     foreach (var attribute in element.Attributes())
58     {
59     XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t{0} {1}: {2}",element.Name, attribute.Name, attribute.Value);
60     }
61     }
62     foreach (var childEllement in element.Descendants())
63     {
64     if (childEllement.HasAttributes)
65     {
66     foreach (var attribute in childEllement.Attributes())
67     {
68     XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t\t{0}: {1}", attribute.Name, attribute.Value);
69     }
70     }
71     XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t\t{0}: {1}", childEllement.Name, childEllement.Value);
72     }
73     }
74     }
75     [Conditional("XMLTV_PARSER_TESTING")]
76     private void ParsePrograms(XDocument doc)
77     {
78     XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Parsing Program Data");
79     }
80     #endregion
81 william 22 }
82     }

  ViewVC Help
Powered by ViewVC 1.1.22