public void ParseSection2()
    {
      // Start and End for tag
      HtmlSectionTemplate template = new HtmlSectionTemplate();
      template.Tags = "T";
      template.Template =
        "<table><tr><td>Title:<#TITLE>(</td><td><#START></td><td><#DESCRIPTION></td><Z(><td><#GENRE></td></Z)?></tr></table>";

      HtmlSectionParser elements = new HtmlSectionParser(template);

      ParserData data = new ParserData();
      IParserData idata = (IParserData)data;
      string source = "<table><tr><td>Test</td><td>123</td><td>blah blah</td></tr></table>";
      elements.ParseSection(source, ref idata);

      Assert.IsTrue(data.GetElement("#TITLE") == "Test");
      Assert.IsTrue(data.GetElement("#START") == "123");
      Assert.IsTrue(data.GetElement("#DESCRIPTION") == "blah blah");

      data = new ParserData();
      idata = (IParserData)data;
      source = "<table><tr><td>Title:Test(1:2)</td><td>123</td><td>blah blah</td></tr></table>";
      elements.ParseSection(source, ref idata);

      Assert.IsTrue(data.GetElement("#TITLE") == "Test");
      Assert.IsTrue(data.GetElement("#START") == "123");
      Assert.IsTrue(data.GetElement("#DESCRIPTION") == "blah blah");
    }
示例#2
0
    public void MatchCount()
    {
      HtmlProfiler profiler;
      int count;

      // Normal test
      HtmlSectionTemplate template = new HtmlSectionTemplate();
      template.Tags = "T";
      template.Template = "<table><tr><td>Test</td><td>1</td><td>2</td></tr></table>";
      profiler = new HtmlProfiler(template);

      count =
        profiler.MatchCount(
          "<table><tr><td>Test</td><td>1</td><td>2</td></tr></table><div><div><div><table><tr><td>Test</td><td>1</td><td>2</td></tr></table><span><span><span><table><tr><td>Test</td><td>1</td><td>2</td><td>3</td></tr></table>");

      Assert.IsTrue(count == 2);

      // Regex test
      template.Template = "<table><tr><td>Test</td><td>1</td><td>2</td><Z(><td>3</td></Z)?></tr></table>";
      profiler = new HtmlProfiler(template);

      count =
        profiler.MatchCount(
          "<table><tr><td>Test</td><td>1</td><td>2</td></tr></table><div><div><div><table><tr><td>Test</td><td>1</td><td>2</td></tr></table><span><span><span><table><tr><td>Test</td><td>1</td><td>2</td><td>3</td></tr></table>");

      Assert.IsTrue(count == 3);
    }
    public void ParseSection3()
    {
      // Multiple tags
      HtmlSectionTemplate template = new HtmlSectionTemplate();
      template.Tags = "T";
      template.Template =
        "<table><tr><td><#TITLE>-<#SUBTITLE></td><td><#START></td><td><#DESCRIPTION></td><Z(><td><#GENRE></td></Z)?></tr></table>";

      HtmlSectionParser elements = new HtmlSectionParser(template);
      ParserData data = new ParserData();
      IParserData idata = (IParserData)data;
      string source = "<table><tr><td>Test-Sub</td><td>123</td><td>blah blah</td></tr></table>";
      elements.ParseSection(source, ref idata);

      Assert.IsTrue(data.GetElement("#TITLE") == "Test");
      Assert.IsTrue(data.GetElement("#SUBTITLE") == "Sub");
      Assert.IsTrue(data.GetElement("#START") == "123");
      Assert.IsTrue(data.GetElement("#DESCRIPTION") == "blah blah");
    }
示例#4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HtmlProfiler"/> class.
 /// </summary>
 /// <param name="template">The template.</param>
 public HtmlProfiler(HtmlSectionTemplate template)
 {
   _sectionTemplate = template;
   _template = BuildProfile(_sectionTemplate.Template);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="HtmlSectionParser"/> class.
 /// </summary>
 /// <param name="template">The template.</param>
 public HtmlSectionParser(HtmlSectionTemplate template)
 {
   _template = template;
   _template.Tags = template.Tags + "Z";
   _templateData = GetSections(template.Template);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="HtmlProfiler"/> class.
 /// </summary>
 /// <param name="template">The template.</param>
 public HtmlProfiler(HtmlSectionTemplate template)
 {
     _sectionTemplate = template;
     _template        = BuildProfile(_sectionTemplate.Template);
 }
示例#7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HtmlSectionParser"/> class.
 /// </summary>
 /// <param name="template">The template.</param>
 public HtmlSectionParser(HtmlSectionTemplate template)
 {
     _template      = template;
     _template.Tags = template.Tags + "Z";
     _templateData  = GetSections(template.Template);
 }