当前位置: 首页>>代码示例>>C#>>正文


C# HtmlTreeMode类代码示例

本文整理汇总了C#中HtmlTreeMode的典型用法代码示例。如果您正苦于以下问题:C# HtmlTreeMode类的具体用法?C# HtmlTreeMode怎么用?C# HtmlTreeMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HtmlTreeMode类属于命名空间,在下文中一共展示了HtmlTreeMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HtmlDomBuilder

 /// <summary>
 /// Creates a new instance of the HTML parser with the specified
 /// document based on the given source manager.
 /// </summary>
 /// <param name="document">
 /// The document instance to be constructed.
 /// </param>
 internal HtmlDomBuilder(HtmlDocument document)
 {
     _tokenizer = new HtmlTokenizer(document.Source, document.Options.Events);
     _document = document;
     _openElements = new List<Element>();
     _templateModes = new Stack<HtmlTreeMode>();
     _formattingElements = new List<Element>();
     _frameset = true;
     _currentMode = HtmlTreeMode.Initial;
 }
开发者ID:JBTech,项目名称:AngleSharp,代码行数:17,代码来源:HtmlDomBuilder.cs

示例2: HtmlDomBuilder

 /// <summary>
 /// Creates a new instance of the HTML parser with the specified
 /// document based on the given source manager.
 /// </summary>
 /// <param name="document">
 /// The document instance to be constructed.
 /// </param>
 internal HtmlDomBuilder(HtmlDocument document)
 {
     var resolver = document.Options.GetService<IEntityService>() ?? HtmlEntityService.Resolver;
     _tokenizer = new HtmlTokenizer(document.Source, document.Options.Events, resolver);
     _document = document;
     _openElements = new List<Element>();
     _templateModes = new Stack<HtmlTreeMode>();
     _formattingElements = new List<Element>();
     _frameset = true;
     _currentMode = HtmlTreeMode.Initial;
 }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:18,代码来源:HtmlDomBuilder.cs

示例3: HtmlDomBuilder

 /// <summary>
 /// Creates a new instance of the HTML parser with the specified
 /// document based on the given source manager.
 /// </summary>
 /// <param name="document">
 /// The document instance to be constructed.
 /// </param>
 public HtmlDomBuilder(HtmlDocument document)
 {
     var options = document.Options;
     var context = document.Context;
     var resolver = options.GetProvider<IEntityProvider>() ?? HtmlEntityService.Resolver;
     _tokenizer = new HtmlTokenizer(document.Source, resolver);
     _tokenizer.Error += (_, error) => context.Fire(error);
     _document = document;
     _openElements = new List<Element>();
     _templateModes = new Stack<HtmlTreeMode>();
     _formattingElements = new List<Element>();
     _frameset = true;
     _currentMode = HtmlTreeMode.Initial;
     _htmlFactory = options.GetFactory<IElementFactory<HtmlElement>>();
     _mathFactory = options.GetFactory<IElementFactory<MathElement>>();
     _svgFactory = options.GetFactory<IElementFactory<SvgElement>>();
 }
开发者ID:Wojdav,项目名称:AngleSharp,代码行数:24,代码来源:HtmlDomBuilder.cs

示例4: InBodyEndTagBody

 /// <summary>
 /// Act as if an body end tag has been found in the InBody state.
 /// </summary>
 /// <param name="token">The actual tag token.</param>
 /// <returns>True if the token was not ignored, otherwise false.</returns>
 Boolean InBodyEndTagBody(HtmlToken token)
 {
     if (IsInScope(TagNames.Body))
     {
         CheckBodyOnClosing(token);
         _currentMode = HtmlTreeMode.AfterBody;
         return true;
     }
     else
     {
         RaiseErrorOccurred(HtmlParseError.BodyNotInScope, token);
         return false;
     }
 }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:19,代码来源:HtmlDomBuilder.cs

示例5: RCDataAlgorithm

 /// <summary>
 /// Follows the generic RCData parsing algorithm.
 /// </summary>
 /// <param name="tag">The given tag token.</param>
 void RCDataAlgorithm(HtmlTagToken tag)
 {
     AddElement(tag);
     _previousMode = _currentMode;
     _currentMode = HtmlTreeMode.Text;
     _tokenizer.State = HtmlParseMode.RCData;
 }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:11,代码来源:HtmlDomBuilder.cs

示例6: BeforeHead

        /// <summary>
        /// See 8.2.5.4.3 The "before head" insertion mode.
        /// </summary>
        /// <param name="token">The passed token.</param>
        void BeforeHead(HtmlToken token)
        {
            switch (token.Type)
            {
                case HtmlTokenType.Character:
                {
                    token.TrimStart();

                    if (token.IsEmpty)
                        return;

                    break;
                }
                case HtmlTokenType.StartTag:
                {
                    var tagName = token.Name;

                    if (tagName.Is(TagNames.Html))
                    {
                        InBody(token);
                        return;
                    }
                    else if (tagName.Is(TagNames.Head))
                    {
                        AddElement(new HtmlHeadElement(_document), token.AsTag());
                        _currentMode = HtmlTreeMode.InHead;
                        return;
                    }

                    break;
                }
                case HtmlTokenType.EndTag:
                {
                    if (TagNames.AllBeforeHead.Contains(token.Name))
                        break;

                    RaiseErrorOccurred(HtmlParseError.TagCannotEndHere, token);
                    return;
                }
                case HtmlTokenType.Comment:
                {
                    CurrentNode.AddComment(token);
                    return;
                }
                case HtmlTokenType.Doctype:
                {
                    RaiseErrorOccurred(HtmlParseError.DoctypeTagInappropriate, token);
                    return;
                }
            }

            BeforeHead(HtmlTagToken.Open(TagNames.Head));
            InHead(token);
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:58,代码来源:HtmlDomBuilder.cs

示例7: InTable

        /// <summary>
        /// See 8.2.5.4.9 The "in table" insertion mode.
        /// </summary>
        /// <param name="token">The passed token.</param>
        void InTable(HtmlToken token)
        {
            switch (token.Type)
            {
                case HtmlTokenType.Comment:
                {
                    CurrentNode.AddComment(token);
                    return;
                }
                case HtmlTokenType.Doctype:
                {
                    RaiseErrorOccurred(HtmlParseError.DoctypeTagInappropriate, token);
                    return;
                }
                case HtmlTokenType.StartTag:
                {
                    var tagName = token.Name;

                    if (tagName.Is(TagNames.Caption))
                    {
                        ClearStackBackTo(TagNames.Table);
                        _formattingElements.AddScopeMarker();
                        AddElement(new HtmlTableCaptionElement(_document), token.AsTag());
                        _currentMode = HtmlTreeMode.InCaption;
                    }
                    else if (tagName.Is(TagNames.Colgroup))
                    {
                        ClearStackBackTo(TagNames.Table);
                        AddElement(new HtmlTableColgroupElement(_document), token.AsTag());
                        _currentMode = HtmlTreeMode.InColumnGroup;
                    }
                    else if (tagName.Is(TagNames.Col))
                    {
                        InTable(HtmlTagToken.Open(TagNames.Colgroup));
                        InColumnGroup(token);
                    }
                    else if (TagNames.AllTableSections.Contains(tagName))
                    {
                        ClearStackBackTo(TagNames.Table);
                        AddElement(new HtmlTableSectionElement(_document, tagName), token.AsTag());
                        _currentMode = HtmlTreeMode.InTableBody;
                    }
                    else if (TagNames.AllTableCellsRows.Contains(tagName))
                    {
                        InTable(HtmlTagToken.Open(TagNames.Tbody));
                        InTableBody(token);
                    }
                    else if (tagName.Is(TagNames.Table))
                    {
                        RaiseErrorOccurred(HtmlParseError.TableNesting, token);

                        if (InTableEndTagTable(token))
                            Home(token);
                    }
                    else if (tagName.Is(TagNames.Input))
                    {
                        var tag = token.AsTag();

                        if (tag.GetAttribute(AttributeNames.Type).Isi(AttributeNames.Hidden))
                        {
                            RaiseErrorOccurred(HtmlParseError.InputUnexpected, token);
                            AddElement(new HtmlInputElement(_document), tag, true);
                            CloseCurrentNode();
                        }
                        else
                        {
                            RaiseErrorOccurred(HtmlParseError.TokenNotPossible, token);
                            InBodyWithFoster(token);
                        }
                    }
                    else if (tagName.Is(TagNames.Form))
                    {
                        RaiseErrorOccurred(HtmlParseError.FormInappropriate, token);

                        if (_currentFormElement == null)
                        {
                            _currentFormElement = new HtmlFormElement(_document);
                            AddElement(_currentFormElement, token.AsTag());
                            CloseCurrentNode();
                        }
                    }
                    else if (TagNames.AllTableHead.Contains(tagName))
                    {
                        InHead(token);
                    }
                    else
                    {
                        RaiseErrorOccurred(HtmlParseError.IllegalElementInTableDetected, token);
                        InBodyWithFoster(token);
                    }

                    return;
                }
                case HtmlTokenType.EndTag:
                {
                    var tagName = token.Name;
//.........这里部分代码省略.........
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:101,代码来源:HtmlDomBuilder.cs

示例8: InCellEndTagCell

        /// <summary>
        /// Act as if an td or th end tag has been found in the InCell state.
        /// </summary>
        /// <param name="token">The actual tag token.</param>
        /// <returns>True if the token was not ignored, otherwise false.</returns>
        Boolean InCellEndTagCell(HtmlToken token)
        {
            if (IsInTableScope(TagNames.AllTableCells))
            {
                GenerateImpliedEndTags();

                if (!TagNames.AllTableCells.Contains(CurrentNode.LocalName))
                    RaiseErrorOccurred(HtmlParseError.TagDoesNotMatchCurrentNode, token);

                ClearStackBackTo(TagNames.AllTableCells);
                CloseCurrentNode();
                _formattingElements.ClearFormatting();
                _currentMode = HtmlTreeMode.InRow;
                return true;
            }
            else
            {
                RaiseErrorOccurred(HtmlParseError.TableCellNotInScope, token);
                return false;
            }
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:26,代码来源:HtmlDomBuilder.cs

示例9: Initial

        /// <summary>
        /// See 8.2.5.4.1 The "initial" insertion mode.
        /// </summary>
        /// <param name="token">The passed token.</param>
        void Initial(HtmlToken token)
        {
            switch (token.Type)
            {
                case HtmlTokenType.Doctype:
                {
                    var doctype = (HtmlDoctypeToken)token;

                    if (!doctype.IsValid)
                        RaiseErrorOccurred(HtmlParseError.DoctypeInvalid, token);

                    _document.AddNode(new DocumentType(_document, doctype.Name ?? String.Empty)
                    {
                        SystemIdentifier = doctype.SystemIdentifier,
                        PublicIdentifier = doctype.PublicIdentifier
                    });

                    if (doctype.IsFullQuirks)
                        _document.QuirksMode = QuirksMode.On;
                    else if (doctype.IsLimitedQuirks)
                        _document.QuirksMode = QuirksMode.Limited;

                    _currentMode = HtmlTreeMode.BeforeHtml;
                    return;
                }
                case HtmlTokenType.Character:
                {
                    token.TrimStart();

                    if (token.IsEmpty)
                        return;

                    break;
                }
                case HtmlTokenType.Comment:
                {
                    _document.AddComment(token);
                    return;
                }
            }

            if (_options.IsEmbedded == false)
            {
                RaiseErrorOccurred(HtmlParseError.DoctypeMissing, token);
                _document.QuirksMode = QuirksMode.On;
            }

            _currentMode = HtmlTreeMode.BeforeHtml;
            BeforeHtml(token);
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:54,代码来源:HtmlDomBuilder.cs

示例10: AfterFrameset

        /// <summary>
        /// See 8.2.5.4.21 The "after frameset" insertion mode.
        /// </summary>
        /// <param name="token">The passed token.</param>
        void AfterFrameset(HtmlToken token)
        {
            switch (token.Type)
            {
                case HtmlTokenType.Character:
                {
                    var str = token.TrimStart();
                    AddCharacters(str);

                    if (token.IsEmpty)
                        return;

                    break;
                }
                case HtmlTokenType.Comment:
                {
                    CurrentNode.AddComment(token);
                    return;
                }
                case HtmlTokenType.Doctype:
                {
                    RaiseErrorOccurred(HtmlParseError.DoctypeTagInappropriate, token);
                    return;
                }
                case HtmlTokenType.StartTag:
                {
                    var tagName = token.Name;

                    if (tagName.Is(TagNames.Html))
                        InBody(token);
                    else if (tagName.Is(TagNames.NoFrames))
                        InHead(token);
                    else
                        break;

                    return;
                }
                case HtmlTokenType.EndTag:
                {
                    if (!token.Name.Is(TagNames.Html))
                        break;

                    _currentMode = HtmlTreeMode.AfterAfterFrameset;
                    return;
                }
                case HtmlTokenType.EndOfFile:
                {
                    End();
                    return;
                }
            }

            RaiseErrorOccurred(HtmlParseError.TokenNotPossible, token);
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:58,代码来源:HtmlDomBuilder.cs

示例11: Reset

        /// <summary>
        /// Resets the current insertation mode to the rules according to the
        /// algorithm specified in 8.2.3.1 The insertion mode.
        /// http://www.w3.org/html/wg/drafts/html/master/syntax.html#the-insertion-mode
        /// </summary>
        void Reset(Element context = null)
        {
            var last = false;
            var node = default(Element);

            for (var i = _openElements.Count - 1; i >= 0; i--)
            {
                node = _openElements[i];

                if (i == 0)
                {
                    last = true;
                    node = context ?? node;
                }

                var tagName = node.LocalName;

                if (tagName.Is(TagNames.Select))
                    _currentMode = HtmlTreeMode.InSelect;
                else if (TagNames.AllTableCells.Contains(tagName))
                    _currentMode = last ? HtmlTreeMode.InBody : HtmlTreeMode.InCell;
                else if (tagName.Is(TagNames.Tr))
                    _currentMode = HtmlTreeMode.InRow;
                else if (TagNames.AllTableSections.Contains(tagName))
                    _currentMode = HtmlTreeMode.InTableBody;
                else if (tagName.Is(TagNames.Body))
                    _currentMode = HtmlTreeMode.InBody;
                else if (tagName.Is(TagNames.Table))
                    _currentMode = HtmlTreeMode.InTable;
                else if (tagName.Is(TagNames.Caption))
                    _currentMode = HtmlTreeMode.InCaption;
                else if (tagName.Is(TagNames.Colgroup))
                    _currentMode = HtmlTreeMode.InColumnGroup;
                else if (tagName.Is(TagNames.Template))
                    _currentMode = _templateModes.Peek();
                else if (tagName.Is(TagNames.Html))
                    _currentMode = HtmlTreeMode.BeforeHead;
                else if (tagName.Is(TagNames.Head))
                    _currentMode = last ? HtmlTreeMode.InBody : HtmlTreeMode.InHead;
                else if (tagName.Is(TagNames.Frameset))
                    _currentMode = HtmlTreeMode.InFrameset;
                else if (last)
                    _currentMode = HtmlTreeMode.InBody;
                else
                    continue;

                break;
            }
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:54,代码来源:HtmlDomBuilder.cs

示例12: Restart

 /// <summary>
 /// Restarts the parser by resetting the internal state.
 /// </summary>
 void Restart()
 {
     _currentMode = HtmlTreeMode.Initial;
     _tokenizer.State = HtmlParseMode.PCData;
     _document.ReplaceAll(null, true);
     _frameset = true;
     _openElements.Clear();
     _formattingElements.Clear();
     _templateModes.Clear();
 }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:13,代码来源:HtmlDomBuilder.cs

示例13: InFrameset

        /// <summary>
        /// See 8.2.5.4.20 The "in frameset" insertion mode.
        /// </summary>
        /// <param name="token">The passed token.</param>
        void InFrameset(HtmlToken token)
        {
            switch (token.Type)
            {
                case HtmlTokenType.Character:
                {
                    var str = token.TrimStart();
                    AddCharacters(str);

                    if (token.IsEmpty)
                        return;

                    break;
                }
                case HtmlTokenType.Comment:
                {
                    CurrentNode.AddComment(token);
                    return;
                }
                case HtmlTokenType.Doctype:
                {
                    RaiseErrorOccurred(HtmlParseError.DoctypeTagInappropriate, token);
                    return;
                }
                case HtmlTokenType.StartTag:
                {
                    var tagName = token.Name;

                    if (tagName.Is(TagNames.Html))
                        InBody(token);
                    else if (tagName.Is(TagNames.Frameset))
                        AddElement(new HtmlFrameSetElement(_document), token.AsTag());
                    else if (tagName.Is(TagNames.Frame))
                    {
                        AddElement(new HtmlFrameElement(_document), token.AsTag(), true);
                        CloseCurrentNode();
                    }
                    else if (tagName.Is(TagNames.NoFrames))
                        InHead(token);
                    else
                        break;

                    return;
                }
                case HtmlTokenType.EndTag:
                {
                    if (!token.Name.Is(TagNames.Frameset))
                        break;

                    if (CurrentNode != _openElements[0])
                    {
                        CloseCurrentNode();

                        if (!IsFragmentCase && !CurrentNode.LocalName.Is(TagNames.Frameset))
                            _currentMode = HtmlTreeMode.AfterFrameset;
                    }
                    else
                        RaiseErrorOccurred(HtmlParseError.CurrentNodeIsRoot, token);

                    return;
                }
                case HtmlTokenType.EndOfFile:
                {
                    if (CurrentNode != _document.DocumentElement)
                        RaiseErrorOccurred(HtmlParseError.CurrentNodeIsNotRoot, token);

                    End();
                    return;
                }
            }

            RaiseErrorOccurred(HtmlParseError.TokenNotPossible, token);
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:77,代码来源:HtmlDomBuilder.cs

示例14: AfterBody

        /// <summary>
        /// See 8.2.5.4.19 The "after body" insertion mode.
        /// </summary>
        /// <param name="token">The passed token.</param>
        void AfterBody(HtmlToken token)
        {
            switch (token.Type)
            {
                case HtmlTokenType.Character:
                {
                    var str = token.TrimStart();
                    ReconstructFormatting();
                    AddCharacters(str);

                    if (token.IsEmpty)
                        return;
                    
                    break;
                }
                case HtmlTokenType.Comment:
                {
                    _openElements[0].AddComment(token);
                    return;
                }
                case HtmlTokenType.Doctype:
                {
                    RaiseErrorOccurred(HtmlParseError.DoctypeTagInappropriate, token);
                    return;
                }
                case HtmlTokenType.StartTag:
                {
                    if (token.Name.Is(TagNames.Html))
                    {
                        InBody(token);
                        return;
                    }

                    break;
                }
                case HtmlTokenType.EndTag:
                {
                    if (token.Name.Is(TagNames.Html))
                    {
                        if (IsFragmentCase)
                            RaiseErrorOccurred(HtmlParseError.TagInvalidInFragmentMode, token);
                        else
                            _currentMode = HtmlTreeMode.AfterAfterBody;

                        return;
                    }

                    break;
                }
                case HtmlTokenType.EndOfFile:
                {
                    End();
                    return;
                }
            }

            RaiseErrorOccurred(HtmlParseError.TokenNotPossible, token);
            _currentMode = HtmlTreeMode.InBody;
            InBody(token);
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:64,代码来源:HtmlDomBuilder.cs

示例15: InRow

        /// <summary>
        /// See 8.2.5.4.14 The "in row" insertion mode.
        /// </summary>
        /// <param name="token">The passed token.</param>
        void InRow(HtmlToken token)
        {
            switch (token.Type)
            {
                case HtmlTokenType.StartTag:
                {
                    var tagName = token.Name;

                    if (TagNames.AllTableCells.Contains(tagName))
                    {
                        ClearStackBackTo(TagNames.Tr);
                        AddElement(token.AsTag());
                        _currentMode = HtmlTreeMode.InCell;
                        _formattingElements.AddScopeMarker();
                    }
                    else if (tagName.Is(TagNames.Tr) || TagNames.AllTableGeneral.Contains(tagName))
                    {
                        if (InRowEndTagTablerow(token))
                            InTableBody(token);
                    }
                    else
                    {
                        break;
                    }

                    return;
                }
                case HtmlTokenType.EndTag:
                {
                    var tagName = token.Name;

                    if (tagName.Is(TagNames.Tr))
                    {
                        InRowEndTagTablerow(token);
                    }
                    else if (tagName.Is(TagNames.Table))
                    {
                        if (InRowEndTagTablerow(token))
                            InTableBody(token);
                    }
                    else if (TagNames.AllTableSections.Contains(tagName))
                    {
                        if (IsInTableScope(tagName))
                        {
                            InRowEndTagTablerow(token);
                            InTableBody(token);
                        }
                        else
                            RaiseErrorOccurred(HtmlParseError.TableSectionNotInScope, token);
                    }
                    else if (TagNames.AllTableSpecial.Contains(tagName))
                    {
                        RaiseErrorOccurred(HtmlParseError.TagCannotEndHere, token);
                    }
                    else
                    {
                        break;
                    }

                    return;
                }
            }

            InTable(token);
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:69,代码来源:HtmlDomBuilder.cs


注:本文中的HtmlTreeMode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。