public static validationResults ValidateAccessibility(string htmlSourceCode) { var diz = new Dictionary<string, object>(); diz.Add("MAX_FILE_SIZE", "52428800"); diz.Add("pastehtml", htmlSourceCode); diz.Add("validate_paste", "Check it"); diz.Add("enable_html_validation", "1"); diz.Add("radio_gid[]", "7"); diz.Add("checkbox_gid[]", "8"); diz.Add("rpt_format", "1"); //diz.Add("enable_html_validation", "1"); using (var resp = FormUpload.MultipartFormDataPost( "http://achecker.ca/checker/index.php", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)", diz )) { using (var str = resp.GetResponseStream()) { HtmlDocument doc = new HtmlDocument(); doc.Load(str); var errorsHtml = doc.DocumentNode.SelectSingleNode(@"//*[@id='AC_errors']"); var errorNodes = errorsHtml.SelectNodes(@"child::*[@class='gd_one_check']"); var errorList = new List<Error>(); if (errorNodes != null) { foreach (var itm in errorNodes) { try { var err = new Error(); err.message = itm.SelectSingleNode(@"child::*[@class='gd_msg']/a").InnerText; err.explanation = itm.SelectSingleNode(@"child::*[@class='gd_question_section']").InnerText; err.explanation = Regex.Replace(err.explanation, @"[\s]+", " "); var location = itm.SelectSingleNode(@"child::table/tr/td/em").InnerText; var m = Regex.Match(location, @"Line\s(?:(?<line>[0-9]+)),\sColumn\s(?:(?<col>[0-9]+))"); err.col = int.Parse(m.Groups["col"].Value); err.line = int.Parse(m.Groups["line"].Value); errorList.Add(err); } catch (Exception ex) { throw ex; } } } var potentialHtml = doc.DocumentNode.SelectSingleNode(@"//*[@id='AC_potential_problems']"); var potenzialNodes = potentialHtml.SelectNodes(@"child::*[@class='gd_one_check']"); var potentialList = new List<Warning>(); if (potenzialNodes != null) { foreach (var itm in potenzialNodes) { try { var message = itm.SelectSingleNode(@"child::*[@class='gd_msg']/a").InnerText; var explanation = itm.SelectSingleNode(@"child::*[@class='gd_question_section']").InnerText; explanation = Regex.Replace(explanation, @"[\s]+", " "); var locations = itm.SelectNodes(@"child::table/tr"); foreach (var l in locations) { var warn = new Warning(); warn.message = message; warn.explanation = explanation; var location = l.SelectSingleNode(@"child::td/em").InnerHtml; var m = Regex.Match(location, @"Line\s(?:(?<line>[0-9]+)),\sColumn\s(?:(?<col>[0-9]+))"); warn.col = m.Groups["col"].Value; warn.line = m.Groups["line"].Value; potentialList.Add(warn); } } catch (Exception ex) { throw ex; } } } var result = new validationResults(); result.Errors = errorList; result.Potentials = new List<WarningPotentialIssue>(); result.Warnings = potentialList; return result; } } }
public static validationResults ValidateSource(string htmlSourceCode) { var diz = new Dictionary<string, object>(); diz.Add("uploaded_file", htmlSourceCode); diz.Add("output", "soap12"); using (var resp = FormUpload.MultipartFormDataPost( "http://validator.w3.org/check", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)", diz )) { using (var str = resp.GetResponseStream()) { var xDoc = XDocument.Load(str); var response = new validationResults(); response.Errors = HTMLFaults(xDoc); var warns = HTMLWarnings(xDoc); response.Warnings = warns.Warnings; response.Potentials = warns.Potentials; return response; } } }