diff --git a/RAE/RAE.csproj b/RAE/RAE.csproj index 3f62a6b..a7cc72c 100644 --- a/RAE/RAE.csproj +++ b/RAE/RAE.csproj @@ -11,11 +11,11 @@ MIT https://github.com/josago97/RAE.NET RAE, Diccionario, España, Español, Lengua, Dictionary, Spain, Spanish, Language - 1.0.2 + 1.0.3 - + diff --git a/RAE/RAEAPI.cs b/RAE/RAEAPI.cs index b0fcd83..f6317ce 100644 --- a/RAE/RAEAPI.cs +++ b/RAE/RAEAPI.cs @@ -1,12 +1,10 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; +using System.Xml; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -57,16 +55,13 @@ public async Task GetKeysAsync(string query) public async Task GetRandomWordAsync() { string response = await _httpClient.GetStringAsync($"{URLBASE}/random"); + XmlDocument xml = new XmlDocument(); + xml.LoadXml($"{response}"); - string idFormat = "article id=\""; - Match idMatch = Regex.Match(response, $@"{idFormat}\w+"); - string id = Regex.Replace(idMatch.Value, idFormat, ""); + string id = xml.DocumentElement.SelectSingleNode("//article").Attributes["id"].Value; + string content = xml.DocumentElement.SelectSingleNode("//header").InnerText; - string contentFormat = "class=\"f\".*?>"; - Match contentMatch = Regex.Match(response, $@"{contentFormat}\w[\,\s\w]*"); - string content = Regex.Replace(contentMatch.Value, contentFormat, ""); - - return new Word(id, HtmlDecode(content)); + return new Word(id, content); } public async Task GetWordOfTheDayAsync()