Sidio.Sitemap.Core 2.3.0

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package Sidio.Sitemap.Core --version 2.3.0
NuGet\Install-Package Sidio.Sitemap.Core -Version 2.3.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sidio.Sitemap.Core" Version="2.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sidio.Sitemap.Core --version 2.3.0
#r "nuget: Sidio.Sitemap.Core, 2.3.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Sidio.Sitemap.Core as a Cake Addin
#addin nuget:?package=Sidio.Sitemap.Core&version=2.3.0

// Install Sidio.Sitemap.Core as a Cake Tool
#tool nuget:?package=Sidio.Sitemap.Core&version=2.3.0

Sidio.Sitemap.Core

Sidio.Sitemap.Core is a lightweight .NET library for generating sitemaps. It supports sitemap index files and can be used in any .NET application. It is written in C# and is available via NuGet.

build NuGet Version

Installation

Add the package to your project.

Usage

Looking for ASP.NET Core integration, see Sidio.Sitemap.AspNetCore.

Sitemap

var nodes = new List<SitemapNode> { new ("https://example.com/page.html") };
var sitemap = new Sitemap(nodes);
var service = new SitemapService(new XmlSerializer());
var xmlResult = service.Serialize();

Sitemap index

var sitemapIndexNodes = new List<SitemapIndexNode> { new("https://example.com/sitemap-1.xml") };
var sitemapIndex = new SitemapIndex(sitemapIndexNodes);
var service = new SitemapIndexService(new XmlSerializer());
var xmlResult = service.Serialize();

Dependency injection

// DI setup
services.AddDefaultSitemapServices();

// implementation
public class MyClass()
{
    public MyClass(ISitemapService service)
    {
        var nodes = new List<SitemapNode> { new ("https://example.com/page.html") };
        var sitemap = new Sitemap(nodes);
        var xmlResult = service.Serialize();
    }
}    

Working with relative URLs

public class MyBaseUrlProvider : IBaseUrlProvider
{
    public Uri BaseUrl => new ("https://example.com", UriKind.Absolute);
}

// DI setup
services.AddBaseUrlProvider<MyBaseUrlProvider>();
services.AddDefaultSitemapServices();
// or in one function:
services.AddDefaultSitemapServices<MyBaseUrlProvider>();

// regular setup
var serializer = new XmlSerializer(new MyBaseUrlProvider());
var service = new SitemapService(serializer);

// nodes, relative urls
var nodes = new List<SitemapNode> { new ("page.html") };

Extensions

Image sitemaps

var sitemap = new Sitemap();
sitemap.Add(new SitemapImageNode("https://example.com/page.html", new ImageLocation("https://example.com/image.png")));

Extension documentation on Google Search Central

News sitemaps

var sitemap = new Sitemap();
sitemap.Add(new SitemapNewsNode("https://example.com/page.html", "title", "name", "EN", DateTimeOffset.UtcNow));

Extension documentation on Google Search Central

Video sitemaps

var video = new VideoContent("https://example.com/thumbnail.png", "title", "description", "https://example.com/video.mp4", null);
var sitemap = new Sitemap();
sitemap.Add(new SitemapVideoNode("https://example.com/page.html", video));

Extension documentation on Google Search Central

Deserialization

It is possible to load existing XML and deserialize it into a sitemap object:

var xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><urlset> ....";
var serializer = services.GetRequiredService<ISitemapSerializer>();
var sitemap = serializer.Deserialize(xml);

Benchmarks XmlSerializer sync/async (Sitemap)


BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3007/23H2/2023Update/SunValley3)
AMD Ryzen 7 5800H with Radeon Graphics, 1 CPU, 16 logical and 8 physical cores
.NET SDK 8.0.101
  [Host]     : .NET 8.0.1 (8.0.123.58001), X64 RyuJIT AVX2
  DefaultJob : .NET 8.0.1 (8.0.123.58001), X64 RyuJIT AVX2


Method NumberOfNodes Mean Error StdDev
Serialize 10 4.316 μs 0.0825 μs 0.0772 μs
SerializeAsync 10 5.367 μs 0.0769 μs 0.0681 μs
Serialize 100 33.616 μs 0.1583 μs 0.1480 μs
SerializeAsync 100 41.328 μs 0.3361 μs 0.3144 μs
Serialize 40000 19,396.188 μs 380.0968 μs 568.9109 μs
SerializeAsync 40000 20,183.385 μs 399.3607 μs 644.8931 μs

References

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Sidio.Sitemap.Core:

Package Downloads
Sidio.Sitemap.AspNetCore The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Sidio.Sitemap.AspNetCore is a lightweight .NET library for generating sitemaps and a sitemap index in ASP .NET Core applications.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.3.0 146 5/19/2024
2.2.4 106 5/2/2024
2.2.3 123 4/20/2024
2.2.2 175 3/28/2024
2.2.1 143 3/22/2024
2.2.0-preview 77 3/22/2024
2.1.0 180 3/15/2024
2.0.0 214 3/14/2024