Skip to content

Instantly share code, notes, and snippets.

@compil3
Created November 6, 2013 04:48
Show Gist options
  • Select an option

  • Save compil3/7331074 to your computer and use it in GitHub Desktop.

Select an option

Save compil3/7331074 to your computer and use it in GitHub Desktop.
public void ParseTeams()
{
HtmlAgilityPack.HtmlNode.ElementsFlags.Remove("option");
var htmlDoc = new HtmlDocument();
htmlDoc.OptionFixNestedTags = true;
htmlDoc.LoadHtml(Source);
var teamName = htmlDoc.DocumentNode
.SelectNodes("//select[@id='team']//option[position() > 1]")
.Select(node => new { team = node.InnerText.Trim(), abbrev = node.Attributes["value"].Value })
.ToList();
var xmlDoc = new XElement("NHL-TEAMS",
new XAttribute("Created", DateTime.Now.ToString()));
foreach (var clean in teamName)
{
xmlDoc = new XElement("TEAM",
new XElement("FULL-NAME", clean.team),
new XElement("ABBREV", clean.abbrev));
Console.WriteLine(clean.team + " " + clean.abbrev);
}
xmlDoc.Save("teams.xml");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment