/[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 27 - (show annotations) (download)
Thu Mar 7 12:11:41 2013 UTC (7 years, 7 months ago) by william
Original Path: trunk/libxmltv/Core/XMLTV_PARSER.cs
File size: 5503 byte(s)
+ basic layout for Program entries

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 public Dictionary<int, IXMLTVProgram> Programs { get; private set; }
28 #endregion
29
30 #region Parser Testing Methods
31 [Conditional("XMLTV_PARSER_TESTING")]
32 private void _imp_TestParse()
33 {
34 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Running XML_PARSER Test");
35 var doc = XMLTV_LOADER.XmlDoc;
36 ParseRootElements(doc);
37 ParseChannels(doc);
38 ParsePrograms(doc);
39 }
40 [Conditional("XMLTV_PARSER_TESTING")]
41 private void ParseRootElements(XDocument doc)
42 {
43 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Parseing Root Data");
44 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));
45 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tRoot: {0}", doc.Root.Name);
46 var attributes = doc.Root.Attributes().ToList();
47 foreach (var attribute in attributes)
48 {
49 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t{0}: {1}", attribute.Name, attribute.Value);
50 }
51 }
52 [Conditional("XMLTV_PARSER_TESTING")]
53 private void ParseChannels(XDocument doc)
54 {
55 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Parsing Channel Data");
56 var elements = doc.Root.Descendants(XMLTV_CONSTANTS.CHANNEL_ELEMENT).ToList();
57 foreach (var element in elements)
58 {
59 if (element.HasAttributes)
60 {
61 foreach (var attribute in element.Attributes())
62 {
63 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t{0} {1}: {2}",element.Name, attribute.Name, attribute.Value);
64 }
65 }
66 foreach (var childEllement in element.Descendants())
67 {
68 if (childEllement.HasAttributes)
69 {
70 foreach (var attribute in childEllement.Attributes())
71 {
72 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t\t{0}: {1}", attribute.Name, attribute.Value);
73 }
74 }
75 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t\t{0}: {1}", childEllement.Name, childEllement.Value);
76 }
77 }
78 }
79 [Conditional("XMLTV_PARSER_TESTING")]
80 private void ParsePrograms(XDocument doc)
81 {
82 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Parsing Program Data");
83 var elements = doc.Root.Descendants(XMLTV_CONSTANTS.PROGRAM_ELEMENT).ToList();
84 foreach (var element in elements)
85 {
86 if (element.HasAttributes)
87 {
88 foreach (var attribute in element.Attributes())
89 {
90 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t{0} {1}: {2}", element.Name, attribute.Name, attribute.Value);
91 }
92 }
93 foreach (var childEllement in element.Descendants())
94 {
95 if (childEllement.HasAttributes)
96 {
97 foreach (var attribute in childEllement.Attributes())
98 {
99 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t\t{0}: {1}", attribute.Name, attribute.Value);
100 }
101 }
102 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t\t{0}: {1}", childEllement.Name, childEllement.Value);
103 }
104 //break;
105 }
106 }
107 #endregion
108
109 #region Creation Methods
110 private void Create()
111 {
112 CreateXMLTVSource();
113 CreateXMLTVChannels();
114 CreateXMLTVPrograms();
115 }
116 private void CreateXMLTVSource()
117 {
118 XMLTVSource source = new XMLTVSource(this);
119 Source = source;
120 }
121 private void CreateXMLTVChannels()
122 {
123 XMLTVChannelCollection channels = new XMLTVChannelCollection(this);
124 Channels = channels.Collection;
125 }
126 private void CreateXMLTVPrograms()
127 {
128 XMLTVProgramCollection programs = new XMLTVProgramCollection(this);
129 Programs = programs.Collection;
130 }
131 #endregion
132 }
133 }

  ViewVC Help
Powered by ViewVC 1.1.22