Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Access ValidationResult.Errors collection to count total accessibility errors found in the document.

using System;

class Program
{
static void Main()
{
try
{
string htmlContent = "<!DOCTYPE html><html><head><title>Sample</title></head><body><img src='image.jpg'></body></html>";
Aspose.Html.HTMLDocument document = new Aspose.Html.HTMLDocument(htmlContent, "about:blank");

Aspose.Html.Accessibility.WebAccessibility webAccessibility = new Aspose.Html.Accessibility.WebAccessibility();
Aspose.Html.Accessibility.AccessibilityValidator validator = webAccessibility.CreateValidator(Aspose.Html.Accessibility.ValidationBuilder.All);
Aspose.Html.Accessibility.Results.ValidationResult validationResult = validator.Validate(document);

int totalErrors = 0;
foreach (Aspose.Html.Accessibility.Results.RuleValidationResult ruleResult in validationResult.Details)
{
if (!ruleResult.Success)
{
foreach (Aspose.Html.Accessibility.ITechniqueResult techResult in ruleResult.Errors)
{
totalErrors++;
}
}
}

Console.WriteLine("Total accessibility errors: " + totalErrors);
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
// Generate a plain‑text summary of validation findings for quick review by developers.
// Access ValidationResult.Warnings collection to count total accessibility warnings reported for the HTML page.

using System;
using System.IO;
using Aspose.Html;
using Aspose.Html.Accessibility;
using Aspose.Html.Accessibility.Results;

class Program
{
static void Main()
{
try
{
// Sample HTML content
string htmlContent = @"<!DOCTYPE html>
<html>
<head><title>Test</title></head>
<body>
<img src='image.jpg' alt=''>
<a href=''>Empty link</a>
</body>
</html>";

// Write the sample HTML to a temporary file
string inputPath = Path.Combine(Path.GetTempPath(), "sample.html");
File.WriteAllText(inputPath, htmlContent);
// Prepare a minimal HTML file
string htmlPath = "sample.html";
string htmlContent = "<!DOCTYPE html><html><head><title>Test</title></head><body><h1>Sample</h1></body></html>";
File.WriteAllText(htmlPath, htmlContent);

// Load the HTML document
using (Aspose.Html.HTMLDocument document = new Aspose.Html.HTMLDocument(inputPath))
using (Aspose.Html.HTMLDocument document = new Aspose.Html.HTMLDocument(htmlPath))
{
// Create WebAccessibility and validator
// Create accessibility validator
Aspose.Html.Accessibility.WebAccessibility webAccessibility = new Aspose.Html.Accessibility.WebAccessibility();
Aspose.Html.Accessibility.AccessibilityValidator validator = webAccessibility.CreateValidator(Aspose.Html.Accessibility.ValidationBuilder.All);

// Perform validation
Aspose.Html.Accessibility.Results.ValidationResult validationResult = validator.Validate(document);

// Count total warnings (if the API exposed a Warnings collection, it would be used here)
int warningsCount = 0;
// The current API version does not provide a direct Warnings collection on ValidationResult.
// If needed, warnings could be derived from detailed results in future versions.

Console.WriteLine($"Validation Success: {validationResult.Success}");
Console.WriteLine($"Total Warnings: {warningsCount}");

if (!validationResult.Success)
{
foreach (Aspose.Html.Accessibility.Results.RuleValidationResult ruleResult in validationResult.Details)
Expand All @@ -42,28 +44,16 @@ static void Main()
Console.WriteLine($"Rule: {ruleResult.Rule.Code} - {ruleResult.Rule.Description}");
foreach (Aspose.Html.Accessibility.ITechniqueResult techResult in ruleResult.Errors)
{
Aspose.Html.Accessibility.IError error = techResult.Error;
Console.WriteLine($" Message: {error.ErrorMessage}");

if (error.Target.TargetType == Aspose.Html.Accessibility.TargetTypes.HTMLElement)
Console.WriteLine($"Error: {techResult.Error.ErrorMessage}");
if (techResult.Error.Target.TargetType == Aspose.Html.Accessibility.TargetTypes.HTMLElement)
{
Aspose.Html.HTMLElement element = (Aspose.Html.HTMLElement)error.Target.Item;
Console.WriteLine($" Element HTML: {element.OuterHTML}");
Aspose.Html.HTMLElement element = (Aspose.Html.HTMLElement)techResult.Error.Target.Item;
Console.WriteLine($"Element: {element.OuterHTML}");
}
}
}
}
}
else
{
Console.WriteLine("Document passed accessibility validation.");
}
}

// Clean up temporary file
if (File.Exists(inputPath))
{
File.Delete(inputPath);
}
}
catch (Exception ex)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Add a missing <track> element with kind="captions" and appropriate src attribute to a video element programmatically.

using System;
using System.IO;
using Aspose.Html;
using Aspose.Html.Collections;
using Aspose.Html.Dom;
using Aspose.Html.Saving;

class Program
{
static void Main(string[] args)
{
try
{
// Prepare sample HTML content with a video element lacking a track
string htmlContent = "<!DOCTYPE html><html><body><video id='myVideo' src='movie.mp4'></video></body></html>";

// Load the HTML document from the string (use two‑argument constructor)
Aspose.Html.HTMLDocument document = new Aspose.Html.HTMLDocument(htmlContent, "about:blank");

// Find all <video> elements
Aspose.Html.Collections.HTMLCollection videos = document.GetElementsByTagName("video");

for (int i = 0; i < videos.Length; i++)
{
Aspose.Html.Dom.Element videoElement = videos[i] as Aspose.Html.Dom.Element;
if (videoElement == null)
continue;

// Create a <track> element for captions
Aspose.Html.Dom.Element trackElement = document.CreateElement("track");
trackElement.SetAttribute("kind", "captions");
trackElement.SetAttribute("src", "captions.vtt");
trackElement.SetAttribute("srclang", "en");
trackElement.SetAttribute("label", "English");

// Append the track to the video element
videoElement.AppendChild(trackElement);
}

// Prepare output directory and file path
string outputDir = Path.Combine(Directory.GetCurrentDirectory(), "Output");
Directory.CreateDirectory(outputDir);
string outputPath = Path.Combine(outputDir, "result.html");

// Save the modified document
Aspose.Html.Saving.HTMLSaveOptions saveOptions = new Aspose.Html.Saving.HTMLSaveOptions();
document.Save(outputPath, saveOptions);

Console.WriteLine("Document saved to: " + outputPath);
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
}

This file was deleted.

Loading
Loading