I created a simple parser to determine the word (pretty sure there are room for improvement):
Solution 1.0
class ParseyMcParseface { /// <summary> /// Word definition lines /// </summary> private string[] _text; /// <summary> /// Constructor (Takes the innerText of the WordDefinition tag as input /// </summary> /// <param name="text">innerText of the WordDefinition</param> public ParseyMcParseface(string text) { _text = text.Split(new [] {'\n'}, StringSplitOptions.RemoveEmptyEntries) .Skip(1) // Skip the first line where the word is mentioned .ToArray(); } /// <summary> /// Convert from single letter type to full human readable type /// </summary> /// <param name="c"></param> /// <returns></returns> private string CharToType(char c) { switch (c) { case 'a': return "Adjective"; case 'n': return "Noun"; case 'v': return "Verb"; default: return "Unknown"; } } /// <summary> /// Reorganize the data for easier parsing /// </summary> /// <param name="text">Lines of text</param> /// <returns></returns> private static List<List<string>> MakeLists(IEnumerable<string> text) { List<List<string>> types = new List<List<string>>(); int i = -1; int j = 0; foreach (var line in text) { // New type (Noun, Verb, Adj.) if (Regex.IsMatch(line.Trim(), "^[avn]{1}\\ \\d+")) { types.Add(new List<string> { line.Trim() }); i++; j = 0; } // New definition in the previous type else if (Regex.IsMatch(line.Trim(), "^\\d+")) { j++; types[i].Add(line.Trim()); } // New line of the same definition else { types[i][j] = types[i][j] + " " + line.Trim(); } } return types; } 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('{', '}')); } defs.Add(new Def() { text = match.Value.Trim(':', '[', ' '), synonym = synonymes }); } definitions.Add(new Definition { type = CharToType(type[0][0]), Def = defs }); } return definitions; } }
And here is a usage example:
WebRequest request = WebRequest.Create("http://services.aonaware.com/DictService/DictService.asmx/DefineInDict"); request.Method = "POST"; 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); dataStream.Close(); WebResponse response = request.GetResponse(); Console.WriteLine(((HttpWebResponse)response).StatusDescription); dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); var doc = new XmlDocument(); doc.LoadXml(responseFromServer ); var el = doc.GetElementsByTagName("WordDefinition"); ParseyMcParseface parseyMcParseface = new ParseyMcParseface(el[1].InnerText); var parsingResult = parseyMcParseface.Parse();
And here is a live demo: https://dotnetfiddle.net/24IQ67
You can also avoid manually searching and then parsing the XML by adding a link to this web service.
Solution 2.0
I made a small application that does this and then parses the definition. Here is posted here on GitHub (it's too big to post here on StackOverflow):
public enum WordTypes { Noun, Verb, Adjective, Adverb, Unknown } public class Definition { public Definition() { Synonyms = new List<string>(); Anotnyms = new List<string>(); } public WordTypes WordType { get; set; } public string DefinitionText { get; set; } public List<string> Synonyms { get; set; } public List<string> Anotnyms { get; set; } } static class DefinitionParser { public static List<Definition> Parse(string wordDefinition) { var wordDefinitionLines = wordDefinition.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries) .Skip(1) .Select(x => x.Trim()) .ToList(); var flatenedList = MakeLists(wordDefinitionLines).SelectMany(x => x).ToList(); var result = new List<Definition>(); foreach (var wd in flatenedList) { var foundMatch = Regex.Match(wd, @"^(?<matchType>adv|adj|v|n){0,1}\s*(\d*): (?<definition>[\w\s;""',\.\(\)\!\-]+)(?<extraInfoSyns>\[syn: ((?<wordSyn>\{[\w\s\-]+\})|(?:[,\ ]))*\]){0,1}\s*(?<extraInfoAnts>\[ant: ((?<wordAnt>\{[\w\s-]+\})|(?:[,\ ]))*\]){0,1}"); var def = new Definition(); if (foundMatch.Groups["matchType"].Success) { var matchType = foundMatch.Groups["matchType"]; def.WordType = DefinitionTypeToEnum(matchType.Value); } if (foundMatch.Groups["definition"].Success) { var definition = foundMatch.Groups["definition"]; def.DefinitionText = definition.Value; } if (foundMatch.Groups["extraInfoSyns"].Success && foundMatch.Groups["wordSyn"].Success) { foreach (Capture capture in foundMatch.Groups["wordSyn"].Captures) { def.Synonyms.Add(capture.Value.Trim('{','}')); } } if (foundMatch.Groups["extraInfoAnts"].Success && foundMatch.Groups["wordAnt"].Success) { foreach (Capture capture in foundMatch.Groups["wordAnt"].Captures) { def.Anotnyms.Add(capture.Value.Trim('{', '}')); } } result.Add(def); } return result; } private static List<List<string>> MakeLists(IEnumerable<string> text) { List<List<string>> types = new List<List<string>>(); int i = -1; int j = 0; foreach (var line in text) { // New type (Noun, Verb, Adj.) if (Regex.IsMatch(line, "^(adj|v|n|adv){1}\\s\\d*")) { types.Add(new List<string> { line }); i++; j = 0; } // New definition in the previous type else if (Regex.IsMatch(line, "^\\d+")) { j++; types[i].Add(line); } // New line of the same definition else { types[i][j] = types[i][j] + " " + line; } } return types; } private static WordTypes DefinitionTypeToEnum(string input) { switch (input) { case "adj": return WordTypes.Adjective; case "adv": return WordTypes.Adverb; case "n": return WordTypes.Noun; case "v": return WordTypes.Verb; default: return WordTypes.Unknown; } } }

Notes:
- This should work as expected.
- Parsing a text message is not reliable.
- You should import the service link (as indicated in another answer) instead of parsing the XML manually.