I have the following table and I want to extract the values Value_1 and Value_2 by matching Description_Line_1 and Description_Line_2.
<table id="tableId" class="tableClass">
<tr>
<th class="thClass1">
Description_Line_1
</th>
<td class="tdClass1">
Value_1
</td>
</tr>
<tr>
<th class="thClass2">
Description_Line_2
</th>
<td class="tdClass2">
Value_2
</td>
</tr>
</table>
The code I came up with is below, but it raises a null reference exception.
string filename = "TableSample.htm";
HtmlDocument doc = new HtmlDocument();
doc.Load(filename);
var tableNode = doc.DocumentNode.SelectSingleNode("//table[@id='tableId' and class='tableClass']//tr");
var value1 = tableNode.SelectSingleNode(".//th[contains(text(),'Description_Line_1')]/td/text()").InnerText;