/[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 25 - (hide annotations) (download)
Thu Mar 7 11:36:00 2013 UTC (7 years, 7 months ago) by william
Original Path: trunk/libxmltv/Core/XMLTV_PARSER.cs
File size: 4876 byte(s)

1 william 25 //#define XMLTV_PARSER_TESTING // when defined will allow calls to be made to _imp_TestParse()
2 william 23 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 william 25 Create();
21 william 22 }
22     #region IXMLTV_PARSER members
23     public IXMLTV_LOADER XMLTV_LOADER { get; private set; }
24 william 23 public void TestParse() { _imp_TestParse(); }
25 william 25 public IXMLTVSource Source { get; private set; }
26 william 22 #endregion
27 william 23
28     #region Parser Testing Methods
29     [Conditional("XMLTV_PARSER_TESTING")]
30     private void _imp_TestParse()
31     {
32     XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Running XML_PARSER Test");
33     var doc = XMLTV_LOADER.XmlDoc;
34     ParseRootElements(doc);
35     ParseChannels(doc);
36     ParsePrograms(doc);
37     }
38     [Conditional("XMLTV_PARSER_TESTING")]
39     private void ParseRootElements(XDocument doc)
40     {
41     XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Parseing Root Data");
42     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));
43     XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tRoot: {0}", doc.Root.Name);
44     var attributes = doc.Root.Attributes().ToList();
45     foreach (var attribute in attributes)
46     {
47     XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t{0}: {1}", attribute.Name, attribute.Value);
48     }
49     }
50     [Conditional("XMLTV_PARSER_TESTING")]
51     private void ParseChannels(XDocument doc)
52     {
53     XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Parsing Channel Data");
54     var elements = doc.Root.Descendants(XMLTV_CONSTANTS.CHANNEL_ELEMENT).ToList();
55     foreach (var element in elements)
56     {
57     if (element.HasAttributes)
58     {
59     foreach (var attribute in element.Attributes())
60     {
61     XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t{0} {1}: {2}",element.Name, attribute.Name, attribute.Value);
62     }
63     }
64     foreach (var childEllement in element.Descendants())
65     {
66     if (childEllement.HasAttributes)
67     {
68     foreach (var attribute in childEllement.Attributes())
69     {
70     XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t\t{0}: {1}", attribute.Name, attribute.Value);
71     }
72     }
73     XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t\t{0}: {1}", childEllement.Name, childEllement.Value);
74     }
75     }
76     }
77     [Conditional("XMLTV_PARSER_TESTING")]
78     private void ParsePrograms(XDocument doc)
79     {
80     XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Parsing Program Data");
81 william 24 var elements = doc.Root.Descendants(XMLTV_CONSTANTS.PROGRAM_ELEMENT).ToList();
82     foreach (var element in elements)
83     {
84     if (element.HasAttributes)
85     {
86     foreach (var attribute in element.Attributes())
87     {
88     XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t{0} {1}: {2}", element.Name, attribute.Name, attribute.Value);
89     }
90     }
91     foreach (var childEllement in element.Descendants())
92     {
93     if (childEllement.HasAttributes)
94     {
95     foreach (var attribute in childEllement.Attributes())
96     {
97     XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t\t{0}: {1}", attribute.Name, attribute.Value);
98     }
99     }
100     XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t\t{0}: {1}", childEllement.Name, childEllement.Value);
101     }
102     //break;
103     }
104 william 23 }
105     #endregion
106 william 25
107     #region Creation Methods
108     private void Create()
109     {
110     CreateXMLTVSource();
111     }
112     private void CreateXMLTVSource()
113     {
114     XMLTVSource source = new XMLTVSource(this);
115     Source = source;
116     }
117     #endregion
118 william 22 }
119     }

  ViewVC Help
Powered by ViewVC 1.1.22