Reputation: 40281
I have a HTML table stored in a string
string tbl = "<table calls='report'><tr><th>head</th><th>name</th></tr><tr><td>Department name</td><td>Mike</th></tr></table>";
how can i loop thru this string and then write it to an XML file?
I think i will be able to write the file to XML but the question is how or loop thru the string and identify whats in t and how to parse it.
Thanks
Upvotes: 1
Views: 402
Reputation: 13965
Since HTML is already XML, you could leave it as it is and meet your objective. But I assume you want semantically meaningful tag names.
You might try the HTML Agility Pack. This allows you to write queries against an object model, similar to the way you can do it with XDocument and Linq-to-XML. I quote:
This is an agile HTML parser that builds a read/write DOM and supports plain XPATH or XSLT (you actually don't HAVE to understand XPATH nor XSLT to use it, don't worry...). It is a .NET code library that allows you to parse "out of the web" HTML files. The parser is very tolerant with "real world" malformed HTML. The object model is very similar to what proposes System.Xml, but for HTML documents (or streams).
It also supports Linq, if you aren't familiar with XPATH et al.
Upvotes: 1