Exemplo n.º 1
0
        //Skip text until the close of a tag, handle also nested tags
        public void SkipToEnd(string tagName)
        {
            Object ch;
            Tag    tag;

            tagName = tagName.ToLower();
            int level = 1;

            while (!parser.Eof())
            {
                ch = parser.Next();
                if (ch is Tag)
                {
                    tag = ch as Tag;
                    if (tag.Name.ToLower().Equals(tagName))
                    {
                        if (tag.Opening)
                        {
                            level++;
                        }
                        if (tag.Closing)
                        {
                            level--;
                            if (level == 0)
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        // Parse the HTML page
        public void Parse(string html)
        {
            Tag    tag;
            Object ch;

            parser        = new HTMLParser();
            parser.Source = html;
            while (!parser.Eof())
            {
                ch = parser.Next();
                if (ch is Tag)
                {
                    tag = ch as Tag;
                    tag = Ignorable(tag);
                    if (tag != null)
                    {
                        AddElement(tag);
                    }
                }
                else
                {
                    string s = ch as string;
                    if (s.Length > 0)
                    {
                        txt.Append(s);
                    }
                }
            }
            Flush();
        }