Skip to content

Parsers for sitemap / sitemap index (aka Sitemaps Protocol)

License

Notifications You must be signed in to change notification settings

toimik/SitemapsProtocol

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ecd89b2 · Jul 15, 2024

History

39 Commits
May 2, 2024
Jul 15, 2024
Jul 15, 2024
Jul 29, 2021
Jul 29, 2021
Jul 29, 2021
Jul 29, 2021
Jul 29, 2021
Jun 28, 2024
Nov 17, 2021

Repository files navigation

Code Coverage Nuget

Toimik.SitemapsProtocol

.NET 8 C# Sitemap parser and Sitemap Index parser.

Quick Start

Installation

Package Manager

PM> Install-Package Toimik.SitemapsProtocol

.NET CLI

> dotnet add package Toimik.SitemapsProtocol

Usage

Sitemap.cs / SitemapIndex.cs

This example shows how to use the Sitemap class.

Usage of the SitemapIndex class is similar.

// The value that every sitemap entry's location must start with
// in order for that entry to be considered as valid
var location = new Uri("http://www.example.com");

// Create an instance of the Sitemap class
var sitemap = new Sitemap(location);

// Load the data from a Stream
using var stream = // Create a local or remote stream
await sitemap.Load(stream);

// Or load the data from a string
// var data = "...";
// sitemap.Load(data);

...

var entries = sitemap.Entries;

Console.WriteLine($"{sitemap.EntryCount} entries parsed:");

// Enumerate the sitemap entries
while (entries.MoveNext())
{
    var entry = entries.Current;
    Console.WriteLine(entry.Location);
    ...
}

SitemapParser.cs / SitemapIndexParser.cs

This example shows how to use the SitemapParser class.

Usage of the SitemapIndexParser class is similar.

var location = new Uri("http://www.example.com");
var parser = new SitemapParser(location);
using var stream = // Create a local or remote stream
await foreach (SitemapEntry entry in parser.Parse(stream))
{
    ...
}

Internally, Sitemap and SitemapIndex use SitemapParser and SitemapIndexParser, respectively.