Is it possible to iterate over all li elements that contain and retrieve their values?
From the OP comment :
Doctype is HTML 5 and it is valid code. - Radu
In this case, you can simply use the following XPath expression :
div
Here, all text nodes that are descendants of all elements lithat are descendants of any element divthat is a child of the current node are selected .
XPath XML ( HTML5 - XML) , , , .
:
using System;
using System.Xml;
class TestXPath
{
static void Main(string[] args)
{
string html5Text =
@"<html>
<head>
</head>
<body>
<div>
<ul>
<li>Line 1</li>
<li>Line 2</li>
<li>Line 3</li>
</ul>
</div>
</body>
</html>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(html5Text);
string xpathExpr = @"/*/*/div//li//text()";
XmlNodeList selection = doc.SelectNodes(xpathExpr);
foreach (XmlNode node in selection)
{
Console.WriteLine(node.OuterXml);
}
}
}
, , , :
Line 1
Line 2
Line 3