Esempio n. 1
0
 public void InsertRange(int startIndex, IHtmlElementsCollection elements)
 {
     foreach (var item in elements)
     {
         Insert(startIndex++, item);
     }
 }
Esempio n. 2
0
 public void AppendRange(IHtmlElementsCollection elements)
 {
     foreach (var item in elements)
     {
         Append(item);
     }
 }
        public void ParseString_ReturnOneElementInCollection_WhenStringContainsOneTag(string html)
        {
            // Arrange

            // Act
            IHtmlElementsCollection elements = htmlParser.ParseString(html);

            // Assert
            Assert.Single(elements.ToList());
        }
 /// <summary>
 /// Try convert html string to IHtmlElementsCollection.
 /// </summary>
 /// <param name="html">Valid html string.</param>
 /// <param name="htmlElements">When the given string is parsed successfully, IHtmlElementsCollection instance represent given html string, otherwise null.</param>
 /// <returns>True, if the given string is parsed successfully, otherwise false.</returns>
 public bool TryParseString(string html, out IHtmlElementsCollection htmlElements)
 {
     try
     {
         htmlElements = ParseString(html);
         return(true);
     }
     catch
     {
         htmlElements = null;
         return(false);
     }
 }
Esempio n. 5
0
 private void SetChildrenParent(IHtmlElementsCollection children)
 {
     foreach (var element in children)
     {
         element.Parents.Add(this);
         if (element is IHtmlNodeElement)
         {
             if (((IHtmlNodeElement)element).Children.Count() > 0)
             {
                 SetChildrenParent(((IHtmlNodeElement)element).Children);
             }
         }
     }
 }
        /// <summary>
        /// Convert html document string to HtmlDocument.
        /// </summary>
        /// <param name="html">Valid html document string.</param>
        /// <returns cref="HtmlDocument">HtmlDocument instance represent given html string.</returns>
        public HtmlDocument ParsePage(string html)
        {
            if (html.IsNullOrEmpty())
            {
                throw new ArgumentNullException("html");
            }

            IHtmlElementsCollection elements = ParseString(html);
            HtmlNodeElement         element  = (HtmlNodeElement)elements.FirstOrDefault(x => x.TagName == "html");
            HtmlDocument            document = new HtmlDocument();

            document.Attributes = element.Attributes;
            document.Children   = element.Children;
            document.Text(element.Texts());
            document.Doctype = (HtmlDocTypeElement)elements.FirstOrDefault(x => x.TagName.IsEqualIgnoreCase("!DOCTYPE"));

            return(document);
        }
Esempio n. 7
0
 /// <summary>
 /// Create html content.
 /// </summary>
 /// <param name="htmlElements">Collection of type IHtmlElement, for convert to HTML content.</param>
 /// <returns>Html content repsresent specified elements collection.</returns>
 public IHtmlContent CreateHtmlContent(IHtmlElementsCollection htmlElements)
 => new HtmlString(String.Join("", htmlElements.Select(element => CreateHtmlContent(element))));