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


C# IDocument.CreateElement方法代码示例

本文整理汇总了C#中IDocument.CreateElement方法的典型用法代码示例。如果您正苦于以下问题:C# IDocument.CreateElement方法的具体用法?C# IDocument.CreateElement怎么用?C# IDocument.CreateElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDocument的用法示例。


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

示例1: CreateEntries

        static IHtmlOrderedListElement CreateEntries(IDocument document, IElement[] headers)
        {
            var toc = document.CreateElement<IHtmlOrderedListElement>();

            // iterate over all elements satisfying the current level in the context
            for (var i = 0; i < headers.Length; ++i)
            {
                // Get the current header
                var header = headers[i];

                // Create the li entry for the element
                var item = CreateEntry(document, header);
                
                // Aggregate possible sub-headers
                var subHeaders = new List<IElement>();

                // As long as we don't see the original header level we'll collect the sub headers
                while (i + subHeaders.Count + 1 < headers.Length && 
                       headers[i].LocalName != headers[i + subHeaders.Count + 1].LocalName)
                {
                    subHeaders.Add(headers[i + 1 + subHeaders.Count]);
                }

                // If we collected any sub headers
                if (subHeaders.Count > 0)
                {
                    // Get another level of ToC (recursively)
                    var subToc = CreateEntries(document, subHeaders.ToArray());

                    // Append the ToC as a child to the current item
                    item.AppendChild(subToc);

                    // Also don't forget to skip these entries
                    i += subHeaders.Count;
                }

                // Add the current item to the ToC
                toc.AppendChild(item);
            }

            return toc;
        }
开发者ID:kk9599,项目名称:AngleSharp.Samples,代码行数:42,代码来源:CreateToc.cs

示例2: CreateEntry

        static IHtmlListItemElement CreateEntry(IDocument document, IElement header)
        {
            // Create a new li element
            var item = document.CreateElement<IHtmlListItemElement>();

            // Initially the text of the li is the same as the h* text
            item.TextContent = header.TextContent;

            // Get a potential (named) anchor here
            var anchor = header.QuerySelector<IHtmlAnchorElement>("a");

            // If there really is an anchor
            if (anchor != null)
            {
                // Get the value of the name attribute
                var name = anchor.GetAttribute("name");

                // If the attribute exists (!= null) and makes sense (not empty)
                if (!String.IsNullOrEmpty(name))
                {
                    // Create a new anchor element
                    anchor = document.CreateElement<IHtmlAnchorElement>();

                    // Set its url to the anchor
                    anchor.Href = "#" + name;

                    // Set the anchor's text content to the header (= item) text
                    anchor.TextContent = item.TextContent;

                    // Replace the text node (= item content) with the anchor
                    item.ReplaceChild(anchor, item.FirstChild);
                }
            }

            return item;
        }
开发者ID:kk9599,项目名称:AngleSharp.Samples,代码行数:36,代码来源:CreateToc.cs

示例3: SimpleTableTest

 private static void SimpleTableTest(IDocument document, IElement group, IElement table)
 {
     var foo1 = group.AppendChild(document.CreateElement("tr")) as IElement;
     foo1.Id = "foo";
     var bar1 = group.AppendChild(document.CreateElement("tr")) as IElement;
     bar1.Id = "bar";
     var foo2 = group.AppendChild(document.CreateElement("tr")) as IElement;
     foo2.Id = "foo";
     var bar2 = group.AppendChild(document.CreateElement("tr")) as IElement;
     bar2.Id = "bar";
     var rows = (table as IHtmlTableElement).Rows;
     Assert.IsNotNull(rows);
     CollectionAssert.AreEquivalent(new[] { foo1, bar1, foo2, bar2 }, rows);
     Assert.AreEqual(foo1, rows["foo"]);
     Assert.AreEqual(bar1, rows["bar"]);
 }
开发者ID:Wojdav,项目名称:AngleSharp,代码行数:16,代码来源:DOMTable.cs

示例4: ConsoleForm

 public ConsoleForm(IDocument document)
     : this(document.Forms.FirstOrDefault() ?? document.CreateElement<IHtmlFormElement>())
 {
 }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:4,代码来源:ConsoleForm.cs


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