コード例 #1
0
ファイル: ParserTest.cs プロジェクト: Carbonfrost/f-html
        public void creates_document_structure()
        {
            string       html = "<meta name=keywords /><link rel=stylesheet /><title>jsoup</title><p>Hello world</p>";
            HtmlDocument doc  = HtmlDocument.Parse(html);
            HtmlElement  head = doc.Head;
            HtmlElement  body = doc.Body;

            Assert.Equal(1, doc.Children.Count);          // root node: contains html node
            Assert.Equal(2, doc.Child(0).Elements.Count); // html node: head and body
            Assert.Equal(3, head.Children.Count);
            Assert.Equal(1, body.Children.Count);

            Assert.Equal("keywords", head.GetElementsByTagName("meta").ToList()[0].Attribute("name"));
            Assert.Equal(0, body.GetElementsByTagName("meta").Count());
            Assert.Equal("jsoup", doc.Title);
            Assert.Equal("Hello world", body.InnerText);
            Assert.Equal("Hello world", body.Children[0].InnerText);
        }