Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Aspose.HTML for .NET provides the Aspose.Html.Accessibility namespace, which is intended for all web accessibility related manipulations and checks. In this article, you will learn how to review the results of web accessibility checks against WCAG compliance, report the criteria tested, and detail specific issues encountered during the validation.
You can learn how to programmatically check website accessibility from the article Accessibility Validator – Website Accessibility Check in C#.
The Aspose.Html.Accessibility.Results namespace contains classes describing the rule validation results. The ValidationResult class is the main class that contains results for all criteria. The ValidationResult object includes a description of the results of checking a document and has properties:
| Property | Description |
|---|---|
| Success | Returns a boolean that says whether the validation succeeded. |
| Details | Returns IList< RuleValidationResult> containing objects of RuleValidationResult with information about validation results. |
| SaveToString() | Save validation results to string |
SaveTo(TextWriter writer) | Saves the validation results in a System.IO.TextWriter object in text format. |
SaveTo(TextWriter writer, ValidationResultSaveFormat format) | Saves the validation results to the System.IO.TextWriter object, where the ValidationResultSaveFormat type parameter specifies in what format the text will be saved. |
Here is a C# code snippet for a web accessibility check. It sets up a validator with specific settings, validates an HTML document, and outputs the validation results to the console:
1// Validate HTML against WCAG rules using C#
2
3// Initialize a webAccessibility container
4WebAccessibility webAccessibility = new WebAccessibility();
5
6// Create an accessibillity validator with static instance for all rules from repository that match the builder settings
7AccessibilityValidator validator = webAccessibility.CreateValidator(ValidationBuilder.All);
8
9// Prepare a path to a source HTML file
10string documentPath = Path.Combine(DataDir, "input.html");
11
12// Initialize an object of the HTMLDocument class
13using (HTMLDocument document = new HTMLDocument(documentPath))
14{
15 // Check the document
16 ValidationResult validationResult = validator.Validate(document);
17
18 // Checking for success
19 if (!validationResult.Success)
20 {
21 // Get a list of RuleValidationResult Details
22 foreach (RuleValidationResult detail in validationResult.Details)
23 {
24 Console.WriteLine("{0}:{1} = {2}", detail.Rule.Code, detail.Rule.Description, detail.Success);
25 }
26 }
27}The code outputs information about accessibility issues to the console, allowing you to identify and address the specific problems in your HTML document.
The RuleValidationResult class – a result of the rule check, contains a list of methods results ITechniqueResult, which are ways to satisfy the success criteria.
| Property | Description |
|---|---|
| Success | Returns a boolean that says whether the validation succeeded. |
| Rule | Returns the checked rule. The rule has a type that implements the IRule interface. |
| Results | Returns a collection of all results, both successful and not. Returns type is IList< ITechniqueResult>. |
| Errors | Returns a collection of results with Errors. Returns type is IList< ITechniqueResult>. |
| Warnings | Returns a collection of results with Warnings. Returns type is IList< ITechniqueResult>. |
The following code iterates through the list of RuleValidationResult objects in the Details property of a validationResult object. Each RuleValidationResult represents the outcome of a specific accessibility rule check during the validation process:
1 // Get a list of RuleValidationResult Details
2 foreach (RuleValidationResult result in validationResult.Details)
3 {
4 Console.WriteLine("{0}:{1} = {2}", result.Rule.Code, result.Rule.Description, result.Success);
5 }Assume the Details contains results for two rules - H37 and H67. The output will be:
1H37:Check alt attributes for images = True
2H67:Check that all forms have labels = FalseThe ITechniqueResult is a public interface that contains information about the result of validation.
| Property | Description |
|---|---|
| Success | Returns a boolean that says whether the validation succeeded. |
| Rule | Returns the checked technique with type of IRule. |
| Error | Returns the object with error. Returns type is IError. |
Below is a C# example of the output of results that did not pass the test of success criteria. We print to the console code description of the criteria, as well as all the details of the execution of the methods of these criteria both successful and with errors:
RuleValidationResult represents a specific accessibility criterion evaluated during validation. The code iterates through the RuleValidationResult objects contained in validationResult.Details.!criterionResult.Success. If the criterion fails, the code reports information about the unsuccessful criterion.Console.WriteLine to print the code and description of the failing criterion.ITechniqueResult objects. These ITechniqueResult objects represent the results of individual rules for the criterion that reported errors.StringBuilder object to format information about the method, including the method code, method success, and method description. 1// Validate HTML accessibility using C# and print all failed WCAG rule with their descriptions
2
3// Initialize a webAccessibility container
4WebAccessibility webAccessibility = new WebAccessibility();
5
6// Create an accessibillity validator with static instance for all rules from repository that match the builder settings
7AccessibilityValidator validator = webAccessibility.CreateValidator(ValidationBuilder.All);
8
9string documentPath = Path.Combine(DataDir, "input.html");
10
11// Initialize an object of the HTMLDocument class
12using (HTMLDocument document = new HTMLDocument(documentPath))
13{
14 // Check the document
15 ValidationResult validationResult = validator.Validate(document);
16
17 // Take a list of rules results
18 foreach (RuleValidationResult ruleResult in validationResult.Details)
19 {
20 // List only unsuccessful rule
21 if (!ruleResult.Success)
22 {
23 // Print the code and description of the rule
24 Console.WriteLine("{0}:{1}", ruleResult.Rule.Code, ruleResult.Rule.Description);
25
26 // Print the results of all methods
27 foreach (ITechniqueResult ruleDetail in ruleResult.Results)
28 {
29 // Print the code and description of the criterions
30 StringBuilder str = new StringBuilder(string.Format("\n{0}: {1} - {2}",
31 ruleDetail.Rule.Code, ruleDetail.Success,
32 ruleDetail.Rule.Description));
33 Console.WriteLine(str.ToString());
34 }
35 }
36 }
37}Using Aspose.HTML for .NET allows you to review the results of web accessibility checks systematically, report the criteria tested, and detail specific issues encountered during the validation process. This is useful for understanding the nature of your web content accessibility problems and taking appropriate action to resolve them.
Aspose.HTML offers free online Web Accessibility Checker. This tool scans web pages, validates them for WCAG compliance, identifies problems, and suggests improvements. Get instant insights into your website’s compliance, allowing you to determine the scope of necessary corrections and the gap between the current state of your website or HTML document and WCAG requirements.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.