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


C# HtmlNodeType类代码示例

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


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

示例1: FindPreviousElement

        public HtmlNode FindPreviousElement(HtmlNode node, HtmlNodeType nodeType)
        {
            if (node.PreviousSibling != null && node.PreviousSibling.NodeType == nodeType)
            {
                return node.PreviousSibling;
            }

            if (node.ParentNode != null && node.ParentNode.NodeType == nodeType)
            {
                return node.ParentNode;
            }

            // Ignoring Text elements
            if (node.PreviousSibling != null && node.PreviousSibling.NodeType == HtmlNodeType.Text)
            {
                return this.FindPreviousElement(node.PreviousSibling, nodeType);
            }

            // Ignoring Text elements
            if (node.ParentNode != null && node.ParentNode.NodeType == HtmlNodeType.Text)
            {
                return this.FindPreviousElement(node.ParentNode, nodeType);
            }

            if (node.ParentNode != null && node.ParentNode.NodeType == nodeType)
            {
                return node.ParentNode;
            }

            return null;
        }
开发者ID:hmeydac,项目名称:Homeworld,代码行数:31,代码来源:HtmlParser.cs

示例2: HtmlNode

 public HtmlNode(HtmlNodeType type, HtmlAgilityPack.HtmlDocument ownerdocument, int index)
     : base(type, ownerdocument, index)
 {
 }
开发者ID:ArjangAssadi,项目名称:HandyUtils,代码行数:4,代码来源:HtmlDocument.cs

示例3: CreateNode

 internal HtmlNode CreateNode(HtmlNodeType type)
 {
     return CreateNode(type, -1);
 }
开发者ID:tstrimple,项目名称:DiscoveryEducation,代码行数:4,代码来源:HtmlDocument.cs

示例4: HtmlNode

        /// <summary>
        /// Initializes HtmlNode, providing type, owner and where it exists in a collection
        /// </summary>
        /// <param name="type"></param>
        /// <param name="ownerdocument"></param>
        /// <param name="index"></param>
        protected HtmlNode(HtmlNodeType type, HtmlDocument ownerdocument, int index)
        {
            _nodetype = type;
            _ownerdocument = ownerdocument;
            _outerstartindex = index;

            switch (type)
            {
                case HtmlNodeType.Comment:
                    Name = HtmlNodeTypeNameComment;
                    _endnode = this;
                    break;

                case HtmlNodeType.Document:
                    Name = HtmlNodeTypeNameDocument;
                    _endnode = this;
                    break;

                case HtmlNodeType.Text:
                    Name = HtmlNodeTypeNameText;
                    _endnode = this;
                    break;
            }

            if (_ownerdocument.Openednodes != null)
            {
                if (!Closed)
                {
                    // we use the index as the key

                    // -1 means the node comes from public
                    if (-1 != index)
                    {
                        _ownerdocument.Openednodes.Add(index, this);
                    }
                }
            }

            if ((-1 != index) || (type == HtmlNodeType.Comment) || (type == HtmlNodeType.Text)) return;
            // innerhtml and outerhtml must be calculated
            _outerchanged = true;
            _innerchanged = true;
        }
开发者ID:AlexanderByndyu,项目名称:HtmlAgilityPack,代码行数:49,代码来源:HtmlNode.cs

示例5: Read

		public bool Read()
		{
			_nodeType = HtmlNodeType.None;
			_name.Length = 0;
			_value.Length = 0;
			_isEmptyElement = false;

			var attrName = new StringBuilder();
			var attrValue = new StringBuilder();

			var quoteStyle = '"';
			var customDoctype = false;
			StringBuilder entity = null;

			while (_peeker.Read())
			{
				char c = _peeker.Current;

				switch (_state)
				{
					case State.Text:
						if (c == '&')
						{
							entity = new StringBuilder();
							_state = State.Amp;
						}
						else if (c == '<')
						{
							_state = State.Lt;
							if (_value.Length > 0)
							{
								_nodeType = HtmlNodeType.Text;
								return true;
							}
						}
						else
						{
							_value.Append(c);
						}
						break;

					case State.Amp:
						if (c == ';')
						{
							_state = State.Text;
							if (entity.Length > 0)
							{
								_value.Append(DecodeEntity("&" + entity + ";"));
							}
							else
							{
								_value.Append("&");
								_value.Append(";");
							}
						}
						else if (c == '#' && entity.Length == 0)
						{
							entity.Append(c);
						}
						else if (Char.IsLetterOrDigit(c))
						{
							entity.Append(c);
						}
						else
						{
							_state = State.Text;
							_peeker.Push(c);
							if (entity.Length > 0)
							{
								_value.Append(DecodeEntity("&" + entity + ";"));
							}
							else
							{
								_value.Append("&");
							}
							entity = null;
						}
						break;

					case State.Lt:
						if (c == '/')
						{
							_state = State.ElemClose;
						}
						else if (c == '?' && _peeker.Match("xml"))
						{
							_state = State.XmlDeclaration;
							_peeker.Read(3);
						}
						else if (c == '?')
						{
							_state = State.Pi;
						}
						else if (c == '!' && _peeker.Match("--"))
						{
							_peeker.Read(2);
							_state = State.Comment;
						}
						else if (c == '!' && _peeker.Match("[CDATA["))
						{
//.........这里部分代码省略.........
开发者ID:lakshithagit,项目名称:Target-Process-Plugins,代码行数:101,代码来源:HtmlReader.cs

示例6: WriteEndElement

		protected override void WriteEndElement(TextWriter result, string name)
		{
			if (!KeepElements.Contains(name))
				return;

			_prevNodeType = HtmlNodeType.None;
			base.WriteEndElement(result, name);
		}
开发者ID:TargetProcess,项目名称:Target-Process-Plugins,代码行数:8,代码来源:CommentHtmlProcessor.cs

示例7: WriteCData

		protected override void WriteCData(TextWriter result, string value)
		{
			_prevNodeType = HtmlNodeType.CDATA;
			base.WriteCData(result, value);
		}
开发者ID:TargetProcess,项目名称:Target-Process-Plugins,代码行数:5,代码来源:CommentHtmlProcessor.cs

示例8: EndTagHandler

        /// <summary>
        /// Start tags handler
        /// </summary>
        /// <param name="context">Markup parsing context</param>
        /// <param name="tag">HTML tag</param>
        private void EndTagHandler(MarkupParsingContext context, HtmlTag tag)
        {
            HtmlNodeType previousNodeType = _currentNodeType;
            string previousTagName;
            IList<HtmlAttribute> previousTagAttributes;
            if (_currentTag != null)
            {
                previousTagName = _currentTag.Name;
                previousTagAttributes = _currentTag.Attributes;
            }
            else
            {
                previousTagName = string.Empty;
                previousTagAttributes = new List<HtmlAttribute>();
            }
            string previousText = _currentText;

            _currentNodeType = HtmlNodeType.EndTag;
            _currentTag = tag;
            _currentText = string.Empty;

            string tagName = tag.Name;
            HtmlTagFlags tagFlags = tag.Flags;

            WhitespaceMinificationMode whitespaceMinificationMode = _settings.WhitespaceMinificationMode;
            if (whitespaceMinificationMode != WhitespaceMinificationMode.None)
            {
                if (_tagsWithNotRemovableWhitespaceQueue.Count == 0 && !tagFlags.EmbeddedCode)
                {
                    // Processing of whitespace, that followed before the end tag
                    bool allowTrimEnd = false;
                    if (tagFlags.Invisible)
                    {
                        allowTrimEnd = true;
                    }
                    else
                    {
                        if (whitespaceMinificationMode == WhitespaceMinificationMode.Medium)
                        {
                            allowTrimEnd = tagFlags.Block;
                        }
                        else if (whitespaceMinificationMode == WhitespaceMinificationMode.Aggressive)
                        {
                            allowTrimEnd = (tagFlags.Block || tagFlags.Inline || tagFlags.InlineBlock);
                        }
                    }

                    if (allowTrimEnd)
                    {
                        TrimEndLastBufferItem();
                    }
                }

                // Check if current tag is in a whitespace queue
                if (_tagsWithNotRemovableWhitespaceQueue.Count > 0 && tagName == _tagsWithNotRemovableWhitespaceQueue.Last())
                {
                    _tagsWithNotRemovableWhitespaceQueue.Dequeue();
                }
            }

            if (_settings.RemoveOptionalEndTags
                && (previousNodeType == HtmlNodeType.EndTag
                    || (previousTagName != tagName && string.IsNullOrWhiteSpace(previousText)))
                && !IsSafeOptionalEndTag(previousTagName))
            {

                if (CanRemoveOptionalTagByParentTagName(previousTagName, tagName))
                {
                    RemoveLastEndTagFromBuffer(previousTagName);
                }
            }

            bool isElementEmpty = (string.IsNullOrWhiteSpace(previousText) && previousTagName == tagName
                && previousNodeType != HtmlNodeType.EndTag);
            if (_settings.RemoveTagsWithoutContent && isElementEmpty
                && CanRemoveTagWithoutContent(previousTagName, previousTagAttributes))
            {
                // Remove last "element" from buffer, return
                if (RemoveLastStartTagFromBuffer(tagName))
                {
                    FlushBuffer();
                    return;
                }
            }

            if (_settings.RemoveOptionalEndTags && tagFlags.OptionalEndTag && IsSafeOptionalEndTag(tagName))
            {
                // Leave only start tag in buffer
                FlushBuffer();
                return;
            }

            // Add end tag to buffer
            _buffer.Add("</");
            _buffer.Add(tagName);
//.........这里部分代码省略.........
开发者ID:jinzesudawei,项目名称:WebMarkupMin,代码行数:101,代码来源:GenericHtmlMinifier.cs

示例9: IfConditionalCommentHandler

        /// <summary>
        /// If conditional comments handler
        /// </summary>
        /// <param name="context">Markup parsing context</param>
        /// <param name="htmlConditionalComment">Conditional comment</param>
        private void IfConditionalCommentHandler(MarkupParsingContext context,
			HtmlConditionalComment htmlConditionalComment)
        {
            _currentNodeType = HtmlNodeType.IfConditionalComment;
            HtmlConditionalCommentType htmlConditionalCommentType = htmlConditionalComment.Type;

            string startPart;
            string endPart;

            switch (htmlConditionalCommentType)
            {
                case HtmlConditionalCommentType.Hidden:
                    startPart = "<!--[if ";
                    endPart = "]>";

                    break;
                case HtmlConditionalCommentType.RevealedValidating:
                    startPart = "<!--[if ";
                    endPart = "]><!-->";

                    break;
                case HtmlConditionalCommentType.RevealedValidatingSimplified:
                    startPart = "<!--[if ";
                    endPart = "]>-->";

                    break;
                case HtmlConditionalCommentType.Revealed:
                    startPart = "<![if ";
                    endPart = "]>";

                    break;
                default:
                    throw new NotSupportedException();
            }

            _buffer.Add(startPart);
            _buffer.Add(htmlConditionalComment.Expression);
            _buffer.Add(endPart);
        }
开发者ID:jinzesudawei,项目名称:WebMarkupMin,代码行数:44,代码来源:GenericHtmlMinifier.cs

示例10: DoctypeHandler

        /// <summary>
        /// Document type declaration handler
        /// </summary>
        /// <param name="context">Markup parsing context</param>
        /// <param name="doctype">Document type declaration</param>
        private void DoctypeHandler(MarkupParsingContext context, string doctype)
        {
            _currentNodeType = HtmlNodeType.Doctype;

            WhitespaceMinificationMode whitespaceMinificationMode = _settings.WhitespaceMinificationMode;
            if (whitespaceMinificationMode != WhitespaceMinificationMode.None)
            {
                // Processing of whitespace, that followed before the document type declaration
                TrimEndLastBufferItem();
            }

            _buffer.Add(_settings.UseShortDoctype ? "<!DOCTYPE html>" : Utils.CollapseWhitespace(doctype));
        }
开发者ID:jinzesudawei,项目名称:WebMarkupMin,代码行数:18,代码来源:GenericHtmlMinifier.cs

示例11: EndIfConditionalCommentHandler

        /// <summary>
        /// End If conditional comments handler
        /// </summary>
        /// <param name="context">Markup parsing context</param>
        /// <param name="type">End If conditional comment type</param>
        private void EndIfConditionalCommentHandler(MarkupParsingContext context, HtmlConditionalCommentType type)
        {
            _currentNodeType = HtmlNodeType.EndIfConditionalComment;

            string endIfComment;

            switch (type)
            {
                case HtmlConditionalCommentType.Hidden:
                    endIfComment = "<![endif]-->";
                    break;
                case HtmlConditionalCommentType.RevealedValidating:
                case HtmlConditionalCommentType.RevealedValidatingSimplified:
                    endIfComment = "<!--<![endif]-->";
                    break;
                case HtmlConditionalCommentType.Revealed:
                    endIfComment = "<![endif]>";
                    break;
                default:
                    throw new NotSupportedException();
            }

            _buffer.Add(endIfComment);
        }
开发者ID:jinzesudawei,项目名称:WebMarkupMin,代码行数:29,代码来源:GenericHtmlMinifier.cs

示例12: CommentHandler

        /// <summary>
        /// Comments handler
        /// </summary>
        /// <param name="context">Markup parsing context</param>
        /// <param name="commentText">Comment text</param>
        private void CommentHandler(MarkupParsingContext context, string commentText)
        {
            _currentNodeType = HtmlNodeType.Comment;

            const int beginCommentLength = 4;
            string processedCommentText = string.Empty;

            if (_noindexCommentRegex.IsMatch(commentText))
            {
                // Processing of noindex comment
                Match noindexCommentMatch = _noindexCommentRegex.Match(commentText);
                processedCommentText = noindexCommentMatch.Groups["closingSlash"].Length > 0 ? "/noindex" : "noindex";
            }
            else if (KnockoutHelpers.IsEndContainerlessComment(commentText))
            {
                // Processing of end Knockout containerless comment
                processedCommentText = "/ko";
            }
            else if (KnockoutHelpers.IsBeginContainerlessComment(commentText))
            {
                // Processing of start Knockout containerless comment
                string koExpression = string.Empty;

                KnockoutHelpers.ParseBeginContainerlessComment(commentText,
                    (localContext, expression) =>
                    {
                        SourceCodeNodeCoordinates expressionCoordinates = localContext.NodeCoordinates;
                        expressionCoordinates.ColumnNumber += beginCommentLength;

                        koExpression = _settings.MinifyKnockoutBindingExpressions ?
                            MinifyKnockoutBindingExpression(context, expressionCoordinates, expression) : expression;
                    }
                );

                processedCommentText = "ko " + koExpression;
            }
            else if (AngularHelpers.IsCommentDirective(commentText))
            {
                // Processing of Angular comment directive
                string ngOriginalDirectiveName = string.Empty;
                string ngNormalizedDirectiveName = string.Empty;
                string ngExpression = string.Empty;

                AngularHelpers.ParseCommentDirective(commentText,
                    (localContext, originalDirectiveName, normalizedDirectiveName) =>
                    {
                        ngOriginalDirectiveName = originalDirectiveName;
                        ngNormalizedDirectiveName = normalizedDirectiveName;
                    },
                    (localContext, expression) =>
                    {
                        SourceCodeNodeCoordinates expressionCoordinates = localContext.NodeCoordinates;
                        expressionCoordinates.ColumnNumber += beginCommentLength;

                        ngExpression = expression;
                        if (_settings.MinifyAngularBindingExpressions
                            && ContainsAngularBindingExpression(ngNormalizedDirectiveName))
                        {
                            ngExpression = MinifyAngularBindingExpression(context, SourceCodeNodeCoordinates.Empty,
                                expressionCoordinates, expression);
                        }
                    }
                );

                processedCommentText = "directive:" + ngOriginalDirectiveName + " " + ngExpression;
            }
            else
            {
                if (!_settings.RemoveHtmlComments)
                {
                    processedCommentText = commentText;
                }
            }

            if (processedCommentText.Length > 0)
            {
                _buffer.Add("<!--");
                _buffer.Add(processedCommentText);
                _buffer.Add("-->");
            }
        }
开发者ID:jinzesudawei,项目名称:WebMarkupMin,代码行数:86,代码来源:GenericHtmlMinifier.cs

示例13: HtmlElementNodeBase

 protected HtmlElementNodeBase(HtmlNodeType type, HtmlDocument ownerdocument, int index)
     : base(type, ownerdocument, index)
 {
 }
开发者ID:ToFuKing,项目名称:HtmlAgilityPack,代码行数:4,代码来源:HtmlElementNodeBase.cs

示例14: SetNodeType

 protected void SetNodeType(HtmlNodeType nodeType)
 {
     this.nodeType = nodeType;
 }
开发者ID:prepare,项目名称:HTML-Renderer,代码行数:4,代码来源:DomNodes.cs

示例15: GetOuterHtml

            /// <summary>
            /// Returns the Html/Xml of the current Element up to its corresponding EndElement, unless the
            /// current Element is an empty element (e.g. ends with a /> and not just a >).  If it is an
            /// empty element, returns only the current Element.
            /// </summary>
            /// <returns>
            /// Returns a <Typ>TextReader</Typ> that gives access to the HTML (or XML as the case may be) from
            /// the current node (which must be an Element node) to the corresponding EndElement
            /// node (or the end of the file if the EndElement doesn't exist.)
            /// </returns>
            /// <remarks>
            /// After calling this method, the state of the parser will be that the current note type is "none."
            /// </remarks>
            /// <exception cref="InvalidOperationException">If the node type isn't an Element node,
            /// or the node's name is blank.</exception>
            internal TextReader GetOuterHtml()
            {
                PlainTextString name = Name;
                // the current node type must be an Element node and have a name.
                if (m_NodeType != HtmlNodeType.Element || String.IsNullOrEmpty(name)) throw new InvalidOperationException();

                // Move m_ParseWriter over to m_GetOuterHtmlWriter so everything gets copied into it, and it never
                // gets replaced (see ReadNextChar() - if m_GetOuterHtmlWriter is non-null, characters get
                // copied into it instead of m_ParseWriter.)
                m_GetOuterHtmlWriter = m_ParseWriter;
                m_ParseWriter = null;

                // Capture the rest of the current Element.  Set m_ParseMode to Skip to avoid saving
                // attribute values.
                m_ParseMode = ParseMode.Skip;
                try
                {
                    while (m_ParseState != HtmlParseState.None) Parse();
                }
                catch (EndOfStreamException)
                {
                    // do nothing
                }

                // If this isn't an empty element, find the corresponding EndElement
                if (!IsEmptyElement)
                {
                    // keep a count of Element node names equivalent to the current node name, to
                    // account for Elements of the same name that are inside the current Element,
                    // in order to stop parsing at the corrent EndElement.
                    int count = 1; // count the current Element
                    while (count > 0 && GetNextNode())
                    {
                        if (m_NodeType == HtmlNodeType.Element && 0 == String.Compare(Name, name, StringComparison.OrdinalIgnoreCase)) count++;
                        else if (m_NodeType == HtmlNodeType.EndElement && 0 == String.Compare(Name, name, StringComparison.OrdinalIgnoreCase)) count--;
                    }
                    // If there is still a count, it means GetNextNode returned false, meaning end of stream.
                    if (count == 0)
                    {
                        // make sure to finish parsing the current node
                        try
                        {
                            while (m_ParseState != HtmlParseState.None)
                            {
                                Parse();
                            }
                        }
                        catch (EndOfStreamException)
                        {
                            // do nothing
                        }
                    }
                }
                // transfer the stream writer's stream into a text reader and return it.
                m_GetOuterHtmlWriter.Flush();
                // the stream is a DetachableStream from the ReadNextChar() method
                DetachableStream detachableStream = (DetachableStream)m_GetOuterHtmlWriter.BaseStream;
                Stream stream = detachableStream.Stream; // the underlying stream
                // detach the stream from the m_GetOuterHtmlWriter
                detachableStream.Detach();
                // position the underlying stream at position 0 and hand it off to the StreamReader
                stream.Position = 0;
                StreamReader reader = new StreamReader(stream, m_GetOuterHtmlWriter.Encoding);
                m_GetOuterHtmlWriter.Dispose();
                m_GetOuterHtmlWriter = null;

                // set the current node type to "none"
                m_NodeType = HtmlNodeType.None;

                // return the reader
                return reader;
            }
开发者ID:supermuk,项目名称:iudico,代码行数:87,代码来源:HtmlTextReader.cs


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