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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/libxmltv/Core/XMLTV_PARSER.cs	2013/03/07 10:20:50	22
+++ trunk/libxmltv/Core/XMLTV_PARSER.cs	2013/03/07 11:08:48	23
@@ -1,13 +1,17 @@
-´╗┐using System;
+´╗┐#define XMLTV_PARSER_TESTING // when defined will allow calls to be made to _imp_TestParse()
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using libxmltv.Interfaces;
+using System.Diagnostics;
+using System.Xml.Linq;
 
 namespace libxmltv.Core
 {
     internal class XMLTV_PARSER : IXMLTV_PARSER
     {
+        
         public XMLTV_PARSER(object xmltv)
         {
             IXMLTV_LOADER _xmltv;
@@ -16,6 +20,63 @@
         }
         #region IXMLTV_PARSER members
         public IXMLTV_LOADER XMLTV_LOADER { get; private set; }
+        public void TestParse() { _imp_TestParse(); }
+        #endregion
+
+        #region Parser Testing Methods
+        [Conditional("XMLTV_PARSER_TESTING")]
+        private void _imp_TestParse()
+        {
+            XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Running XML_PARSER Test");
+            var doc = XMLTV_LOADER.XmlDoc;
+            ParseRootElements(doc);
+            ParseChannels(doc);
+            ParsePrograms(doc);
+        }
+        [Conditional("XMLTV_PARSER_TESTING")]
+        private void ParseRootElements(XDocument doc)
+        {
+            XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Parseing Root Data");            
+            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));
+            XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tRoot: {0}", doc.Root.Name);
+            var attributes = doc.Root.Attributes().ToList();
+            foreach (var attribute in attributes)
+            {
+                XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t{0}: {1}", attribute.Name, attribute.Value);
+            }
+        }
+        [Conditional("XMLTV_PARSER_TESTING")]
+        private void ParseChannels(XDocument doc)
+        {
+            XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Parsing Channel Data");
+            var elements = doc.Root.Descendants(XMLTV_CONSTANTS.CHANNEL_ELEMENT).ToList();
+            foreach (var element in elements)
+            {
+                if (element.HasAttributes)
+                {
+                    foreach (var attribute in element.Attributes())
+                    {
+                        XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t{0} {1}: {2}",element.Name, attribute.Name, attribute.Value);
+                    }
+                } 
+                foreach (var childEllement in element.Descendants())
+                {
+                    if (childEllement.HasAttributes)
+                    {
+                        foreach (var attribute in childEllement.Attributes())
+                        {
+                            XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t\t{0}: {1}", attribute.Name, attribute.Value);
+                        }
+                    }
+                    XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t\t{0}: {1}", childEllement.Name, childEllement.Value);
+                }
+            }
+        }
+        [Conditional("XMLTV_PARSER_TESTING")]
+        private void ParsePrograms(XDocument doc)
+        {
+            XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Parsing Program Data");
+        }
         #endregion
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22