Пример #1
0
        public void TestTagName()
        {
            string html = @"<body><h1>title</h1>message</body>";
            HtmlDocument doc = new HtmlDocument(html);

            var q = new HtmlNavigator( doc )
                .Where( n => n.TagName == "h1" )
                .Select( n => n );
            Assert.AreEqual(1, q.Count());
            Assert.AreEqual("title", q.First().Value );
        }
Пример #2
0
        public void TestTagName()
        {
            string       html = @"<body><h1>title</h1>message</body>";
            HtmlDocument doc  = new HtmlDocument(html);

            var q = new HtmlNavigator(doc)
                    .Where(n => n.TagName == "h1")
                    .Select(n => n);

            Assert.AreEqual(1, q.Count());
            Assert.AreEqual("title", q.First().Value);
        }
Пример #3
0
        public void TestTagName2()
        {
            string html = @"<body><h2>title1</h2>message<h2>title2</h2></body>";
            HtmlDocument doc = new HtmlDocument(html);

            var q = new HtmlNavigator(doc)
                .Where(n => n.TagName == "h2")
                .Select(n => n);

            Assert.AreEqual(2, q.Count());
            Assert.AreEqual("title1", q.First().Value);
            Assert.AreEqual("title2", q.ToList()[1].Value);
        }
Пример #4
0
        public void TestTagName2()
        {
            string       html = @"<body><h2>title1</h2>message<h2>title2</h2></body>";
            HtmlDocument doc  = new HtmlDocument(html);

            var q = new HtmlNavigator(doc)
                    .Where(n => n.TagName == "h2")
                    .Select(n => n);

            Assert.AreEqual(2, q.Count());
            Assert.AreEqual("title1", q.First().Value);
            Assert.AreEqual("title2", q.ToList()[1].Value);
        }
Пример #5
0
        public void TestTagName4()
        {
            string       html = @"
<body>
    <h2>title1</h2>
        <span id='msg1'>message</span>
    <h2>title2</h2>
        <span id='msg2'>message2</span>
</body>
";
            HtmlDocument doc  = new HtmlDocument(html);

            var q = new HtmlNavigator(doc)
                    .Where(n => n % "id" == "msg2")
                    .Select(n => n);

            Assert.AreEqual(1, q.Count());
            Assert.AreEqual("message2", q.First().Value);
        }
Пример #6
0
        public void TestRemove1()
        {
            string html = @"
            <body>
            <h2>title1</h2>
            <span id='m1'>message</span>
            <h2>title2</h2>
            <span id='m2'>message2</span>
            </body>
            ";
            HtmlDocument doc = new HtmlDocument(html);
            var q = new HtmlNavigator(doc)
                .Where(n => n % "id" == "m2")
                .Remove();

            q = new HtmlNavigator(doc)
                .Where(n => n.TagName == "span")
                .Select(n => n);

            Assert.AreEqual(1, q.Count());
            Assert.AreEqual("message", q.Item().Value);
        }
Пример #7
0
        public void TestRemove1()
        {
            string       html = @"
<body>
    <h2>title1</h2>
    <span id='m1'>message</span>
    <h2>title2</h2>
    <span id='m2'>message2</span>
</body>
";
            HtmlDocument doc  = new HtmlDocument(html);
            var          q    = new HtmlNavigator(doc)
                                .Where(n => n % "id" == "m2")
                                .Remove();

            q = new HtmlNavigator(doc)
                .Where(n => n.TagName == "span")
                .Select(n => n);

            Assert.AreEqual(1, q.Count());
            Assert.AreEqual("message", q.Item().Value);
        }
Пример #8
0
        public void TestTagName4()
        {
            string html = @"
            <body>
            <h2>title1</h2>
            <span id='msg1'>message</span>
            <h2>title2</h2>
            <span id='msg2'>message2</span>
            </body>
            ";
            HtmlDocument doc = new HtmlDocument(html);

            var q = new HtmlNavigator(doc)
                .Where(n => n % "id" == "msg2")
                .Select(n => n);

            Assert.AreEqual(1, q.Count());
            Assert.AreEqual("message2", q.First().Value);
        }