Esempio n. 1
0
        public void Add(HtmlObject content)
        {
            Requires.NotNull(content, nameof(content));
            if (ReferenceEquals(this, content.Parent))
            {
                throw new InvalidOperationException("Cannot have a duplicate element or attribute");
            }

            if (content is HtmlNode)
            {
                if (ReferenceEquals(this, content))
                {
                    throw new InvalidOperationException("Cannot add an object as a child to itself.");
                }
                ThrowIfVoid();
                AddNodeAfter(this, _nodes._last, (HtmlNode)content);
            }
            else if (content is HtmlAttribute)
            {
                HtmlAttribute attribute = (HtmlAttribute)content;
                if (HasAttribute(attribute.Name))
                {
                    throw new InvalidOperationException("Cannot have a duplicate element or attribute.");
                }
                AddAttribute(attribute);
            }
            else
            {
                throw new ArgumentException("The object to add was not a node or attribute", nameof(content));
            }
        }
Esempio n. 2
0
        public IEnumerable <HtmlNode> NextNodes()
        {
            HtmlObject nextNode = _next;

            while (nextNode != null)
            {
                yield return((HtmlNode)nextNode);

                nextNode = nextNode._next;
            }
        }
Esempio n. 3
0
        public IEnumerable <HtmlNode> PreviousNodes()
        {
            HtmlObject previousNode = _previous;

            while (previousNode != null)
            {
                yield return((HtmlNode)previousNode);

                previousNode = previousNode._previous;
            }
        }
Esempio n. 4
0
        public IEnumerable <HtmlNode> Nodes()
        {
            HtmlObject node = _nodes._first;

            while (node != null)
            {
                yield return((HtmlNode)node);

                node = node._next;
            }
        }
Esempio n. 5
0
        public IEnumerable <HtmlElement> PreviousElements(string tag)
        {
            bool isDefaultTag = string.IsNullOrEmpty(tag);

            HtmlObject previousNode = _previous;

            while (previousNode != null)
            {
                HtmlElement previousElement = previousNode as HtmlElement;
                if (previousElement != null && (isDefaultTag || StringExtensions.EqualsAsciiOrdinalIgnoreCase(previousElement.Tag, tag)))
                {
                    yield return(previousElement);
                }
                previousNode = previousNode._previous;
            }
        }
Esempio n. 6
0
        public IEnumerable <HtmlElement> NextElements(string tag)
        {
            bool isDefaultTag = string.IsNullOrEmpty(tag);

            HtmlObject nextNode = _next;

            while (nextNode != null)
            {
                HtmlElement nextElement = nextNode as HtmlElement;
                if (nextElement != null && (isDefaultTag || StringExtensions.EqualsAsciiOrdinalIgnoreCase(nextElement.Tag, tag)))
                {
                    yield return(nextElement);
                }
                nextNode = nextNode._next;
            }
        }
Esempio n. 7
0
        public IEnumerable <HtmlElement> Descendants(string tag)
        {
            bool isDefaultTag = string.IsNullOrEmpty(tag);

            HtmlObject node = _nodes._first;

            while (node != null)
            {
                HtmlElement element = node as HtmlElement;
                if (element != null)
                {
                    if (isDefaultTag || StringExtensions.EqualsAsciiOrdinalIgnoreCase(element.Tag, tag))
                    {
                        yield return(element);
                    }
                    foreach (HtmlElement child in element.Descendants(tag))
                    {
                        yield return(child);
                    }
                }
                node = node._next;
            }
        }
Esempio n. 8
0
 public static T WithChild <T>(this T self, HtmlObject element) where T : HtmlElement
 {
     self.Add(element);
     return(self);
 }