Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i want to get data from an html file into a Dictionary. The html file contains several tables. But every table contains just 2 colloumns. I have tried already the html-aglility-pack parser but i cant find any useful documentary about tables. Here is a part of the html file:

XML
<TR><TD><TD><TD COLSPAN=3><B>CPU Physical Info:</B>
<TR><TD><TD><TD><TD>Package Type&nbsp;&nbsp;<TD>775 Contact FC-LGA8
<TR><TD><TD><TD><TD>Package Size&nbsp;&nbsp;<TD>37.5 mm x 37.5 mm
<TR><TD><TD><TD><TD>Transistors&nbsp;&nbsp;<TD>456 million
<TR><TD><TD><TD><TD>Process Technology&nbsp;&nbsp;<TD>45 nm, CMOS, Cu, High-K Gate
<TR><TD><TD><TD><TD>Die Size&nbsp;&nbsp;<TD>164 mm2
<TR><TD><TD><TD><TD>Core Voltage&nbsp;&nbsp;<TD>1.100 - 1.262 V
<TR><TD><TD><TD><TD>I/O Voltage&nbsp;&nbsp;<TD>1.100 - 1.262 V
<TR><TD><TD><TD><TD>Typical Power&nbsp;&nbsp;<TD>95 W @ 2.83 GHz
<TR><TD>&nbsp;



Thank you
Posted

1 solution

Refer- create a dictionary or list from string(HTML tag included) in C#[^]. One example is there.
Quote:

You should use the HTML Agility Pack.


For example: (Tested)


C#
var doc = new HtmlDocument();
doc.LoadHtml(s);
var dict = doc.DocumentNode.Descendants("tr")
              .ToDictionary(
                  tr => int.Parse(tr.Descendants("td").First().InnerText),
                  tr => int.Parse(tr.Descendants("td").Last().InnerText)
              );

If the HTML will always be well-formed, you can use LINQ-to-XML; the code would be almost identical.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900