This project has moved. For the latest updates, please go here.

Extract Description HTML rows

Oct 13, 2012 at 11:50 PM

The Description Feature may contain custom user fields encoded as an html-table, e.g.

<table><tr><td valign="top">Description</td><td>Some description</td></tr><tr bgcolor='34bbbb'><td valign="top">Day</td><td>21 sep 2010</td></tr>...

I would like to suggest to add another method to the Description class (or Feature), to extract these values. It may be something like this if we use HtmlAgilityPack :


IEnumerable<Tuple<string, string>> ExtractHtmlRowsData(Description description)   {           

var document = new HtmlAgilityPack.HtmlDocument();           


foreach (var row in document.DocumentNode.SelectNodes("//tr"))            {               

var cells = row.SelectNodes("td").Select(n => n.InnerText).ToArray();               

if (cells.Length == 2) yield return new Tuple<string, string>(cells[0], cells[1]);                }           


Oct 14, 2012 at 7:30 PM

Thanks for the code (which somebody might find useful as an extension method) but I'm not sure parsing of HTML data is the responsibility of a KML parser.

If you can alter how the KML is generated you might want to look into storing the data in ExtendedData.

The library can do the inverse of what you're asking, though, and turn this extended data into a HTML table (this was for compatibility with libkml; the HTML generation is very basic/crude but matches the C++ code this library was based on) by using the CreateBalloonText method of the SharpKml.Engine.EntityMapper class.