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


C# HtmlElement.Elements方法代码示例

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


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

示例1: ReplaceAll

        public void ReplaceAll(HtmlObject[] content)
        {
            HtmlElement parent = new HtmlElement("parent", new HtmlElement("element"), new HtmlAttribute("attribute1"), new HtmlAttribute("attribute2"), new HtmlComment("comment"));

            parent.ReplaceAll(content);
            Assert.Equal(content.OfType<HtmlElement>().ToArray(), parent.Elements().ToArray());
            Assert.Equal(content.OfType<HtmlAttribute>().ToArray(), parent.Attributes().ToArray());
            Assert.Equal(parent.Elements().Count() + parent.Attributes().Count(), parent.ElementsAndAttributes().Count());
            Assert.Equal(parent.Nodes().Count() + parent.Attributes().Count(), parent.NodesAndAttributes().Count());
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:10,代码来源:HtmlElement.ReplaceTests.cs

示例2: Ctor_String_ParamsHtmlObject

 public void Ctor_String_ParamsHtmlObject(HtmlObject[] content)
 {
     HtmlElement element = new HtmlElement("element", content);
     Assert.Equal("element", element.Tag);
     Assert.False(element.IsVoid);
     Assert.Equal(content.OfType<HtmlElement>().ToArray(), element.Elements().ToArray());
     Assert.Equal(content.OfType<HtmlAttribute>().ToArray(), element.Attributes().ToArray());
     Assert.Equal(content.OfType<HtmlNode>().ToArray(), element.Nodes().ToArray());
     Assert.Equal(element.Elements().Count() + element.Attributes().Count(), element.ElementsAndAttributes().Count());
     Assert.Equal(content.Length, element.NodesAndAttributes().Count());
 }
开发者ID:hughbe,项目名称:html-generator,代码行数:11,代码来源:HtmlElementTests.cs

示例3: Add_HtmlObject

        public void Add_HtmlObject(bool isVoid)
        {
            HtmlElement parent = new HtmlElement("parent", isVoid);

            // Atribute
            HtmlAttribute attribute = new HtmlAttribute("attribute");
            parent.Add(attribute);
            Assert.Equal(parent, attribute.Parent);
            Assert.Equal(new HtmlAttribute[] { attribute }, parent.Attributes());

            if (!isVoid)
            {
                // Element
                HtmlElement element = new HtmlElement("element");
                parent.Add(element);
                Assert.Equal(parent, element.Parent);
                Assert.Equal(new HtmlElement[] { element }, parent.Elements());

                // Nodes
                HtmlComment comment = new HtmlComment("comment");
                parent.Add(comment);
                Assert.Equal(parent, comment.Parent);
                Assert.Equal(new HtmlObject[] { element, comment }, parent.Nodes());
            }
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:25,代码来源:HtmlElement.AddTests.cs

示例4: Add_ParamsHtmlObject_Empty

 public void Add_ParamsHtmlObject_Empty()
 {
     HtmlElement element = new HtmlElement("parent");
     element.Add(new HtmlObject[0]);
     Assert.Empty(element.Elements());
     Assert.Empty(element.Attributes());
 }
开发者ID:hughbe,项目名称:html-generator,代码行数:7,代码来源:HtmlElement.AddTests.cs

示例5: Ctor_String_Bool

 public void Ctor_String_Bool(string tag, bool isVoid, string expectedTag)
 {
     HtmlElement element = new HtmlElement(tag, isVoid);
     Assert.Equal(expectedTag, element.Tag);
     Assert.Equal(isVoid, element.IsVoid);
     Assert.Empty(element.Elements());
     Assert.Empty(element.Attributes());
     Assert.Empty(element.ElementsAndAttributes());
 }
开发者ID:hughbe,项目名称:html-generator,代码行数:9,代码来源:HtmlElementTests.cs

示例6: Ctor_String

 public void Ctor_String(string tag, string expectedTag)
 {
     HtmlElement element = new HtmlElement(tag);
     Assert.Equal(expectedTag, element.Tag);
     Assert.False(element.IsVoid);
     Assert.Empty(element.Elements());
     Assert.Empty(element.Attributes());
     Assert.Empty(element.ElementsAndAttributes());
 }
开发者ID:hughbe,项目名称:html-generator,代码行数:9,代码来源:HtmlElementTests.cs

示例7: Add_ParamsHtmlObject_VoidElement

        public void Add_ParamsHtmlObject_VoidElement()
        {
            HtmlElement element = new HtmlElement("parent", isVoid: true);
            HtmlAttribute attribute1 = new HtmlAttribute("attribute1");
            HtmlAttribute attribute2 = new HtmlAttribute("attribute2");
            element.Add(new HtmlObject[] { attribute1, attribute2 });

            Assert.Equal(element, attribute1.Parent);
            Assert.Equal(element, attribute2.Parent);
            Assert.Empty(element.Elements());
            Assert.Equal(new HtmlAttribute[] { attribute1, attribute2 }, element.Attributes());
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:12,代码来源:HtmlElement.AddTests.cs

示例8: Add_ParamsHtmlObject_NonVoidElement

        public void Add_ParamsHtmlObject_NonVoidElement()
        {
            HtmlElement parent = new HtmlElement("parent");
            HtmlElement element = new HtmlElement("element");
            HtmlAttribute attribute = new HtmlAttribute("attribute");
            HtmlComment comment = new HtmlComment("comment");
            parent.Add(new HtmlObject[] { element, attribute, comment });

            Assert.Equal(parent, element.Parent);
            Assert.Equal(parent, attribute.Parent);
            Assert.Equal(new HtmlObject[] { element }, parent.Elements());
            Assert.Equal(new HtmlAttribute[] { attribute }, parent.Attributes());
            Assert.Equal(new HtmlObject[] { element, comment }, parent.Nodes());
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:14,代码来源:HtmlElement.AddTests.cs

示例9: AddFirst_NonEmptyHtmlObject

        public void AddFirst_NonEmptyHtmlObject(bool isVoid)
        {
            HtmlElement parent = new HtmlElement("parent", isVoid);
            HtmlAttribute attribute1 = new HtmlAttribute("attribute1");
            parent.Add(attribute1);

            // Attributes
            HtmlAttribute attribute2 = new HtmlAttribute("attribute2");
            parent.AddFirst(attribute2);
            Assert.Equal(parent, attribute2.Parent);
            Assert.Equal(new HtmlAttribute[] { attribute2, attribute1 }, parent.Attributes());

            if (!isVoid)
            {
                HtmlElement element1 = new HtmlElement("element1");
                parent.Add(element1);

                // Elements
                HtmlElement element2 = new HtmlElement("element2");
                parent.AddFirst(element2);
                Assert.Equal(parent, element2.Parent);
                Assert.Equal(new HtmlElement[] { element2, element1 }, parent.Elements());

                // Nodes
                HtmlComment comment = new HtmlComment("comment");
                parent.AddFirst(comment);
                Assert.Equal(parent, comment.Parent);
                Assert.Equal(new HtmlObject[] { comment, element2, element1 }, parent.Nodes());
            }
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:30,代码来源:HtmlElement.AddTests.cs

示例10: AddFirst_IEnumerableHtmlObject_Empty

 public void AddFirst_IEnumerableHtmlObject_Empty()
 {
     HtmlElement element = new HtmlElement("parent");
     element.AddFirst(new HtmlObject[0]);
     Assert.Empty(element.Elements());
     Assert.Empty(element.Attributes());
 }
开发者ID:hughbe,项目名称:html-generator,代码行数:7,代码来源:HtmlElement.AddTests.cs

示例11: AddFirst_ElementHasDifferentParent_RemovesFromOldParent

        public void AddFirst_ElementHasDifferentParent_RemovesFromOldParent()
        {
            HtmlElement parent = new HtmlElement("parent");
            HtmlElement child1 = new HtmlElement("child1");
            HtmlElement granchild1 = new HtmlElement("grandchild1");
            HtmlElement granchild2 = new HtmlElement("grandchild2");
            HtmlElement granchild3 = new HtmlElement("grandchild3");
            HtmlElement child2 = new HtmlElement("child2");

            parent.Add(child1, child2);
            child1.Add(granchild1, granchild2, granchild3);

            child2.Add(granchild1);
            Assert.Equal(child2, granchild1.Parent);
            Assert.Equal(new HtmlElement[] { granchild1 }, child2.Elements());
            Assert.Equal(new HtmlElement[] { granchild2, granchild3 }, child1.Elements());

            child2.Add(granchild2);
            Assert.Equal(child2, granchild2.Parent);
            Assert.Equal(new HtmlElement[] { granchild1, granchild2 }, child2.Elements());
            Assert.Equal(new HtmlElement[] { granchild3 }, child1.Elements());

            child2.Add(granchild3);
            Assert.Equal(child2, granchild3.Parent);
            Assert.Equal(new HtmlElement[] { granchild1, granchild2, granchild3 }, child2.Elements());
            Assert.Empty(child1.Elements());
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:27,代码来源:HtmlElement.AddTests.cs

示例12: Elements_String_ReturnsExpected

        public void Elements_String_ReturnsExpected()
        {
            HtmlElement element1 = new HtmlElement("element1");
            HtmlElement element2 = new HtmlElement("element1");
            HtmlElement element3 = new HtmlElement("element2");

            HtmlElement parent = new HtmlElement("element", element1, element2, element3);
            Assert.Equal(new HtmlElement[] { element1, element2 }, parent.Elements("element1"));
            Assert.Equal(new HtmlElement[] { element1, element2 }, parent.Elements("ELEMENT1"));
            Assert.Equal(new HtmlElement[] { element3 }, parent.Elements("element2"));
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:11,代码来源:HtmlElement.ReadTests.cs

示例13: AddFirst_IEnumerableHtmlObject_VoidElement

        public void AddFirst_IEnumerableHtmlObject_VoidElement()
        {
            HtmlElement element = new HtmlElement("parent");
            HtmlAttribute attribute1 = new HtmlAttribute("attribute1");
            element.Add(attribute1);

            HtmlAttribute attribute2 = new HtmlAttribute("attribute2");
            HtmlAttribute attribute3 = new HtmlAttribute("attribute3");
            element.AddFirst((IEnumerable<HtmlObject>)new HtmlObject[] { attribute2, attribute3 });

            Assert.Equal(element, attribute2.Parent);
            Assert.Equal(element, attribute3.Parent);
            Assert.Empty(element.Elements());
            Assert.Equal(new HtmlAttribute[] { attribute3, attribute2, attribute1 }, element.Attributes());
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:15,代码来源:HtmlElement.AddTests.cs

示例14: ReplaceNodesIEnumerableHtmlElement

        public void ReplaceNodesIEnumerableHtmlElement(HtmlElement[] elements)
        {
            HtmlElement parent = new HtmlElement("parent", new HtmlElement("element"), new HtmlAttribute("attribute1"), new HtmlAttribute("attribute2"));

            parent.ReplaceNodes(elements);
            Assert.Equal(elements, parent.Elements().ToArray());
            Assert.Equal(2, parent.Attributes().Count());
            Assert.Equal(elements.Length + 2, parent.ElementsAndAttributes().Count());
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:9,代码来源:HtmlElement.ReplaceTests.cs

示例15: Elements_String_IgnoresAttributes_IgnoresNodes

        public void Elements_String_IgnoresAttributes_IgnoresNodes()
        {
            HtmlElement element1 = new HtmlElement("element1");
            HtmlElement element2 = new HtmlElement("element2");
            HtmlElement parent = new HtmlElement("parent", element1, new HtmlComment("element1"), new HtmlAttribute("element1"), element2);

            Assert.Equal(new HtmlElement[] { element1 }, parent.Elements("element1"));
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:8,代码来源:HtmlElement.ReadTests.cs


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