using System.Collections.Generic;
using System.Text.RegularExpressions;
public static void Main()
WebRequest request = WebRequest.Create("http://services.aonaware.com/DictService/DictService.asmx/DefineInDict");
string postData = "dictId=wn&word=abandon";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
WebResponse response = request.GetResponse();
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
var doc = new XmlDocument();
doc.LoadXml(responseFromServer);
XmlNode el = doc.GetElementsByTagName("WordDefinition")[1];
ParseyMcParseface parseyMcParseface = new ParseyMcParseface(el.InnerText);
var parsingResult = parseyMcParseface.Parse();
foreach(var r in parsingResult){
Console.WriteLine(r.type);
foreach(var def in r.Def){
Console.WriteLine("\t" + def.text);
foreach(var s in def.synonym){
Console.WriteLine("\t\t" + s);
public ParseyMcParseface(string text)
_text = text.Split(new [] {'\n'}, StringSplitOptions.RemoveEmptyEntries)
private string CharToType(char c)
private static List<List<string>> MakeLists(IEnumerable<string> text)
List<List<string>> types = new List<List<string>>();
foreach (var line in text)
if (Regex.IsMatch(line.Trim(), "^[avn]{1}\\ \\d+"))
types.Add(new List<string> { line.Trim() });
else if (Regex.IsMatch(line.Trim(), "^\\d+"))
types[i].Add(line.Trim());
types[i][j] = types[i][j] + " " + line.Trim();
public List<Definition> Parse()
var definitionsLines = MakeLists(_text);
List<Definition> definitions = new List<Definition>();
foreach (var type in definitionsLines)
var defs = new List<Def>();
foreach (var def in type)
var match = Regex.Match(def.Trim(), "(?:\\:\\ )(\\w|\\ |;|\"|,|\\.|-)*[\\[]{0,1}");
MatchCollection syns = Regex.Matches(def.Trim(), "\\{(\\w|\\ )+\\}");
List<string> synonymes = new List<string>();
foreach (Match syn in syns)
synonymes.Add(syn.Value.Trim('{', '}'));
text = match.Value.Trim(':', '[', ' '),
definitions.Add(new Definition
type = CharToType(type[0][0]),
public string text { get; set; }
public List<string> synonym { get; set; }
public string type { get; set; }
public List<Def> Def { get; set; }