Exemple #1
0
        private void OpenTag(HtmlNodeOpenTag openTag)
        {
            _node = null;
            // tag : <P> <br> <a> <img>
            switch (openTag.Name.ToLower())
            {
            case "p":
                _node = new HtmlDocNodeBeginTag()
                {
                    Tag = HtmlTagType.P, Index = ++_nodeIndex, Line = openTag.Line, Column = openTag.Column
                };
                break;

            case "br":
                _node = new HtmlDocNodeTag()
                {
                    Tag = HtmlTagType.BR, Index = ++_nodeIndex, Line = openTag.Line, Column = openTag.Column
                };
                break;

            case "a":
                _node = new HtmlDocNodeBeginTagA()
                {
                    Index = ++_nodeIndex, Line = openTag.Line, Column = openTag.Column
                };
                break;

            case "img":
                _node = new HtmlDocNodeTagImg()
                {
                    Index = ++_nodeIndex, Line = openTag.Line, Column = openTag.Column
                };
                break;
            }
        }
Exemple #2
0
        public IEnumerable <HtmlDocNode> Read()
        {
            foreach (HtmlNode node in _nodes)
            {
                switch (node.Type)
                {
                case HtmlNodeType.OpenTag:
                    OpenTag((HtmlNodeOpenTag)node);
                    break;

                case HtmlNodeType.CloseTag:
                    if (_node != null)
                    {
                        yield return(_node);

                        _node = null;
                    }
                    break;

                case HtmlNodeType.Property:
                    Property((HtmlNodeProperty)node);
                    break;

                case HtmlNodeType.EndTag:
                    // for tag <img ... />
                    if (_node != null)
                    {
                        yield return(_node);

                        _node = null;
                    }
                    EndTag((HtmlNodeEndTag)node);
                    if (_node != null)
                    {
                        yield return(_node);

                        _node = null;
                    }
                    break;

                case HtmlNodeType.Text:
                    HtmlNodeText nodeText = (HtmlNodeText)node;
                    if (!nodeText.IsTextSeparator)
                    {
                        yield return new HtmlDocNodeText()
                               {
                                   Text = nodeText.Text, Index = ++_nodeIndex, Line = node.Line, Column = node.Column
                               }
                    }
                    ;
                    break;
                }
            }
        }
Exemple #3
0
        private void EndTag(HtmlNodeEndTag endTag)
        {
            _node = null;
            switch (endTag.Name.ToLower())
            {
            case "p":
                _node = new HtmlDocNodeEndTag()
                {
                    Tag = HtmlTagType.P, Index = ++_nodeIndex, Line = endTag.Line, Column = endTag.Column
                };
                break;

            case "a":
                _node = new HtmlDocNodeEndTag()
                {
                    Tag = HtmlTagType.A, Index = ++_nodeIndex, Line = endTag.Line, Column = endTag.Column
                };
                break;
            }
        }