Xdot.Sitemap 4.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Xdot.Sitemap --version 4.0.0                
NuGet\Install-Package Xdot.Sitemap -Version 4.0.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="Xdot.Sitemap" Version="4.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Xdot.Sitemap --version 4.0.0                
#r "nuget: Xdot.Sitemap, 4.0.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 Xdot.Sitemap as a Cake Addin
#addin nuget:?package=Xdot.Sitemap&version=4.0.0

// Install Xdot.Sitemap as a Cake Tool
#tool nuget:?package=Xdot.Sitemap&version=4.0.0                

A package for .NET to help you build a sitemap according to the google recommendations. see this link to learn about sitemaps.

**if you like this work, please consider give the project star 🌟 on GitHub **

Installation

Using the .NET CLI tools:

dotnet add package Xdot.Sitemap

Using the NuGet CLI:

nuget install Xdot.Sitemap

Using the Package Manager Console:

Install-Package Xdot.Sitemap

Usage

Write a sitemap to stream

var urls = new List<SitemapUrl> 
{
    new("https://www.example.com"),
    new("https://www.example.com/contact-us"),
}

await using var stream = new MemoryStream();
await urls.WriteToAsync(stream);

This code will write the following to the memory stream:

<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://www.example.com</loc>
  </url>
  <url>
    <loc>https://www.example.com/contact-us</loc>
  </url>
</urlset>

Write localized versions for a URL

var urls = new List<SitemapUrl> 
{
    new(new SitemapAlternateUrl[] 
    {
        new() 
        {
            Location = "https://www.example.com/english/page.html",
            LanguageCode = "en",
        },
        new() 
        {
            Location = "https://www.example.com/deutsch/page.html",
            LanguageCode = "de",
        },
        new() 
        {
            Location = "https://www.example.com/schweiz-deutsch/page.html",
            LanguageCode = "de-ch",
        },
    }),
    
    // ...
};

await using var stream = new MemoryStream();
await urls.WriteToAsync(stream);

This code will write the following to the memory stream:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://www.example.com/english/page.html</loc>
    <xhtml:link rel="alternate" hreflang="en" href="https://www.example.com/english/page.html" />
    <xhtml:link rel="alternate" hreflang="de" href="https://www.example.com/deutsch/page.html" />
    <xhtml:link rel="alternate" hreflang="de-ch" href="https://www.example.com/schweiz-deutsch/page.html" />
  </url>
  <url>
    <loc>https://www.example.com/deutsch/page.html</loc>
    <xhtml:link rel="alternate" hreflang="en" href="https://www.example.com/english/page.html" />
    <xhtml:link rel="alternate" hreflang="de" href="https://www.example.com/deutsch/page.html" />
    <xhtml:link rel="alternate" hreflang="de-ch" href="https://www.example.com/schweiz-deutsch/page.html" />
  </url>
  <url>
    <loc>https://www.example.com/schweiz-deutsch/page.html</loc>
    <xhtml:link rel="alternate" hreflang="en" href="https://www.example.com/english/page.html" />
    <xhtml:link rel="alternate" hreflang="de" href="https://www.example.com/deutsch/page.html" />
    <xhtml:link rel="alternate" hreflang="de-ch" href="https://www.example.com/schweiz-deutsch/page.html" />
  </url>
</urlset>

Write Sitemap Index

var sitemapReferences = new List<SitemapReference> 
{
    new() { Location = "https://www.Example.com/ümlaT-sitemap.xml" },
    new() { Location = "https://www.example.com/اداره-اعلانات" },
}

await using var stream = new MemoryStream()
await references.WriteToAsync(stream);

This code will write the following to the memory stream:

<?xml version="1.0" encoding="utf-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap>
    <loc>https://www.example.com/%C3%BCmlat-sitemap.xml</loc>
  </sitemap>
  <sitemap>
    <loc>https://www.example.com/%D8%A7%D8%AF%D8%A7%D8%B1%D9%87-%D8%A7%D8%B9%D9%84%D8%A7%D9%86%D8%A7%D8%AA</loc>
  </sitemap>
</sitemapindex>

License

This project is licensed under the Apache 2.0 license.

Contact

If you have any suggestions, comments or questions, please feel free to contact me on:

Email: mxshaheen@gmail.com

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.3 419 10/6/2022
4.0.2-preview.0.2 97 10/6/2022
4.0.1 469 7/29/2022
4.0.0 390 8/18/2021
3.10.21 407 6/18/2021
3.10.1-preview.0.2 174 6/18/2021
3.9.2-preview.0.3 185 5/24/2021
3.9.1 371 5/7/2021
3.9.0 349 4/26/2021
3.8.1 341 4/16/2021
3.8.0 375 4/9/2021
3.7.0 370 4/9/2021