itsWindows11/OwlCore.Storage.HttpExtensions

Extensions for the HTTP implementation of the OwlCore.Storage abstraction, including enumerating site content in file/folder structure using sitemaps.

★ 0Forks 0C#GitHub ↗Compare

README

OwlCore.Storage.HttpExtensions

NuGet Build and Test

OwlCore.Storage.HttpExtensions adds HTTP-based sitemap support for OwlCore.Storage. It includes types for reading sitemap XML, representing sitemap files and folders, and a sample console app for exploring sitemap URLs.

Projects

  • src/OwlCore.Storage.HttpExtensions - the class library that parses sitemap content and exposes sitemap file/folder types.
  • src/OwlCore.Storage.HttpExtensions.Tests - unit tests for the library.
  • SitemapReaderSampleApp - a console app that reads and prints sitemap contents from a URL.

Library

The library provides HTTP sitemap parsing for direct sitemap URLs, nested sitemap indexes, and plain-text sitemap lists. It is designed to work with OwlCore.Storage-compatible file and folder abstractions.

Features

  • Reads XML sitemap indexes and URL sets.
  • Reads plain-text sitemap lists.
  • Streams sitemap XML from the HTTP response instead of buffering the entire document.
  • Exposes sitemap files and folders through OwlCore.Storage-compatible types.
  • Supports direct sitemap URLs and nested sitemap indexes.
  • Offers APIs for callers that already have an XmlReader.

Sample usage

using System.Xml;
using OwlCore.Storage.HttpExtensions;

var client = new HttpClient();
var folder = new HttpSitemapFolder(client, new Uri("https://www.sitemaps.org/sitemap.xml"));

await foreach (var item in folder.GetItemsAsync())
{
	Console.WriteLine(item.Uri);
}

using var stream = await client.GetStreamAsync("https://www.sitemaps.org/sitemap.xml");
using var reader = XmlReader.Create(stream, new XmlReaderSettings
{
	Async = true,
	IgnoreComments = true,
	IgnoreWhitespace = true,
});

await foreach (var item in folder.GetItemsAsync(reader))
{
	Console.WriteLine(item.Uri);
}

Sample app

The sample app accepts a sitemap URL and can optionally recurse into nested sitemap indexes.

Usage

SitemapReaderSampleApp --help
SitemapReaderSampleApp <url>
SitemapReaderSampleApp <url> --recursive
SitemapReaderSampleApp --url <url> --recursive

Options

  • -h, --help, /? - show help text.
  • -u, --url <url> - specify the sitemap URL.
  • -r, --recursive - recursively traverse nested sitemap indexes.

Examples

dotnet run --project SitemapReaderSampleApp -- https://www.sitemaps.org/sitemap.xml
dotnet run --project SitemapReaderSampleApp -- https://www.sitemaps.org/sitemap.xml --recursive
dotnet run --project SitemapReaderSampleApp -- --help

Output

The console app prints the sitemap tree to standard output. Folder-like sitemap indexes are shown as [folder] entries, and URL entries are shown as [file] entries.

When --recursive is enabled, the console app walks nested sitemap indexes using an iterative stack-based traversal.

Build and test

dotnet build
dotnet test

Contributors

itsWindows11

Issues