internal override bool IsValidNode(HtmlNode node)
        {
            if (node == null)
            {
                return false;
            }

            if (node.Parent == null)
            {
                return false;
            }

            bool isValid = false;

            foreach (HtmlNode child in node.GetParent().GetChildren())
            {
                if (child.Tag == HtmlTag.TEXT && child.Html.Trim() == string.Empty)
                {
                    continue;
                }

                //Find first child tag which matches the node's tag. The break statement will discard the loop after finding the first matching node.
                //If the node is the first child, it will apply the styles.
                isValid = string.Compare(node.Tag, child.Tag, StringComparison.InvariantCultureIgnoreCase) == 0 && node == child;

                //The loop only needs to check the first child element except the empty text element. So we can skip here.
                break;

            }

            return isValid;
        }
        internal override bool IsValidNode(HtmlNode node)
        {
            if (node == null)
            {
                return false;
            }

            if (node.Tag == HtmlTag.TEXT)
            {
                return false;
            }

            if (node.Parent == null)
            {
                return false;
            }

            bool isValid = true;

            foreach (HtmlNode child in node.GetParent().GetChildren())
            {
                //There is a non text node other than current node. So the selector is not valid
                if (child != node && child.Tag != HtmlTag.TEXT)
                {
                    isValid = false;
                    break;
                }
            }

            return isValid;
        }
		private bool FinilizeNodes(int position, ref HtmlNode current)
		{
			if (current != null)
			{
				current.Finilize(position);

				while (current.Parent != null)
				{
					current = current.GetParent();
					current.Finilize(position);
				}
			}

			return current != null;
		}
        internal override bool IsValidNode(HtmlNode node)
        {
            if (node == null)
            {
                return false;
            }

            if (this.position == -1)
            {
                return false;
            }

            HtmlNode parent = node.GetParent();

            if (parent == null)
            {
                return false;
            }

            int childrenCount = 0;
            int nodeIndex = 0;

            foreach (HtmlNode child in parent.GetChildren())
            {
                if (child.Tag == HtmlTag.TEXT)
                {
                    continue;
                }

                ++childrenCount;

                if (child == node)
                {
                    nodeIndex = childrenCount;
                }
            }

            if (childrenCount < this.position)
            {
                return false;
            }

            return (childrenCount - position) + 1 == nodeIndex;
        }
        internal override bool IsValidNode(HtmlNode node)
        {
            bool isValid = false;

            if (node != null && node.Parent != null)
            {
                HtmlNode lastChild = null;

                foreach (HtmlNode child in node.GetParent().GetChildren())
                {
                    if (string.Compare(node.Tag, child.Tag, StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        lastChild = child;
                    }
                }

                isValid = lastChild != null && lastChild == node;
            }

            return isValid;
        }
        private string FindParentStyle(HtmlNode node, string styleName)
        {
            string value = string.Empty;
            bool found = false;

            foreach (HtmlStyle style in node.HtmlStyles)
            {
                if (string.Compare(styleName, style.Name, StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    found = true;
                    value = style.Value;
                }
            }

            if (!found && node.Parent != null)
            {
                value = FindParentStyle(node.GetParent(), styleName);
            }

            return value;
        }
        private bool CloseOpenedChilds(HtmlNode current, string closeTag, int textEnd, int htmlEnd, ref HtmlNode newNode)
        {
            bool tagFound = false;

            if (current != null)
            {
                if (string.Compare(current.Tag, closeTag, StringComparison.InvariantCultureIgnoreCase) == 0 && current.IsOpened)
                {
                    current.SetBoundary(textEnd, htmlEnd);
                    newNode = current;
                    return true;
                }

                tagFound = CloseOpenedChilds(current.GetParent(), closeTag, textEnd, htmlEnd, ref newNode);

                if (tagFound)
                {
                    current.Finilize(textEnd);
                }
            }

            return tagFound;
        }
        internal void CloseNonNestedParents(int htmlStart, string tag, IAnalyzerContext context, ref HtmlNode parent)
        {
            if (parent == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(tag) || string.IsNullOrEmpty(parent.Tag))
            {
                return;
            }

            List<string> parentTags;

            if (nonNestedTags.TryGetValue(tag.Trim().ToLower(), out parentTags))
            {
                if (parentTags.Contains(parent.Tag.Trim().ToLower()))
                {
                    parent.SetBoundary(htmlStart, htmlStart);
                    context.PreviousNode = parent;
                    parent = parent.GetParent();
                }
            }
        }
        bool IAttachedSelector.IsValidNode(HtmlNode node)
        {
            if (node == null)
            {
                return false;
            }

            bool isValid = false;

            HtmlNode parent = node.GetParent();

            if (parent == null)
            {
                return false;
            }

            HtmlNode lastChild = null;

            foreach (HtmlNode child in parent.GetChildren())
            {
                if (child.Tag != HtmlTag.TEXT)
                {
                    lastChild = child;
                }
            }

            if (lastChild != null && lastChild == node)
            {
                isValid = true;
            }
            return isValid;
        }
        internal override bool IsValidNode(HtmlNode node)
        {
            if (node == null)
            {
                return false;
            }

            if (this.position == -1)
            {
                return false;
            }

            if (node.Parent == null)
            {
                return false;
            }

            var parent = node.GetParent();

            if (parent.GetChildren().Count() < this.position)
            {
                return false;
            }

            HtmlNode pNode = GetNodeAtPosition(position, parent);

            if (pNode == null)
            {
                return false;
            }

            return pNode == node;
        }