Skip to content

Instantly share code, notes, and snippets.

@pinscript
Created August 21, 2012 07:29
Show Gist options
  • Select an option

  • Save pinscript/3413106 to your computer and use it in GitHub Desktop.

Select an option

Save pinscript/3413106 to your computer and use it in GitHub Desktop.
private static Dictionary<string, Dictionary<string, string>> Parse(string xpath)
{
var results = new Dictionary<string, Dictionary<string, string>>();
var parts = xpath.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
foreach(var part in parts)
{
var itemName = part.Substring(0, part.IndexOf('['));
var properties = Regex.Matches(part, "@([a-zA-Z]+)='([a-zA-Z]+)'");
var result = properties.Cast<Match>().ToDictionary(p => p.Groups[1].Value, p => p.Groups[2].Value);
results.Add(itemName, result);
}
return results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment