Hi
I have the html below and essentially want to build a Dictionary<string, string> object to use later on. Building the dictionary is no problem, it's the Linq to build a series of id : value nodes that I am struggling with.
<html><body><table>
<tr><td>FirstName</td><td>Bob</td></tr>
<tr><td>LastName</td><td>Smith</td></tr>
<tr><td>Age</td><td></td></tr>
<tr><td>Employed</td><td>Y</td></tr>
</table></body></html>
Desired Results:
I have the html below and essentially want to build a Dictionary<string, string> object to use later on. Building the dictionary is no problem, it's the Linq to build a series of id : value nodes that I am struggling with.
<html><body><table>
<tr><td>FirstName</td><td>Bob</td></tr>
<tr><td>LastName</td><td>Smith</td></tr>
<tr><td>Age</td><td></td></tr>
<tr><td>Employed</td><td>Y</td></tr>
</table></body></html>
Desired Results:
var nodes = doc.DocumentNode.DescendantsAndSelf("tr"); //<==Help here!
// looping through the nodes:
// the XPath interfaces can return null when no nodes are found
Dictionary<string, string> fields = new Dictionary<string, string>();
if (nodes != null)
{
foreach (var node in nodes)
{
var id = node.Id;
var value = node.Attributes["value"].Value;
fields.Add(id, value);
}
}
Thanks in advance