Quantcast
Channel: htmlagilitypack Forum Rss Feed
Viewing all articles
Browse latest Browse all 450

New Post: Newbie Select Question

$
0
0
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:
        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

Viewing all articles
Browse latest Browse all 450

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>