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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 26 - (show annotations) (download)
Thu Mar 7 11:58:34 2013 UTC (7 years, 7 months ago) by william
Original Path: trunk/libxmltv/Core/XMLTV_PARSER.cs
File size: 5199 byte(s)
+ implement channel parsing

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

  ViewVC Help
Powered by ViewVC 1.1.22