5 releases

0.2.1 Feb 7, 2024
0.2.0 Nov 8, 2022
0.1.2 Sep 10, 2022
0.1.1 Sep 6, 2022
0.1.0 Sep 3, 2022

#164 in Parser implementations

Download history 74/week @ 2023-12-22 118/week @ 2023-12-29 375/week @ 2024-01-05 270/week @ 2024-01-12 281/week @ 2024-01-19 187/week @ 2024-01-26 215/week @ 2024-02-02 227/week @ 2024-02-09 211/week @ 2024-02-16 282/week @ 2024-02-23 337/week @ 2024-03-01 313/week @ 2024-03-08 289/week @ 2024-03-15 271/week @ 2024-03-22 312/week @ 2024-03-29 283/week @ 2024-04-05

1,228 downloads per month

MIT license

972 lines


Version Docs License

A Rust library to generate URL, Index, Image, Video, and News sitemaps.


Generates sitemaps

Validates sitemap data

There are a bunch of restrictions as to what data your sitemaps can hold. This library surfaces these validation issues at struct instantiation time. Now you don't have to wait for Google Search Console or Bing Webmaster Tools to alert you of sitemap issues before you can fix data problems.


  • URL Sitemap
    • TooManyUrls
      • Can only contain as many as 50,000 <url>.
    • TooMuchNews
      • Can only contain as many as 1,000 <news: news>.
    • PriorityTooLow and PriorityTooHigh
      • A <priority> must be between 0.0 and 1.0 (inclusive).
    • TooManyImages
      • Can only contain as many as 1,000 <image: image>.
  • Index Sitemap
    • TooManySitemaps
      • Can only contain as many as 50,000 <sitemap>.
  • Video Sitemap
    • DescriptionTooLong
      • A <description> must be no longer than 2048 characters.
    • DurationTooShort and DurationTooLong
      • A <duration> must be between 1 and 28,800 seconds (inclusive).
    • RatingTooLow and RatingTooHigh
      • A <rating> must be between 0.0 and 5.0 (inclusive).
    • UploaderNameTooLong
      • An <uploader>'s <name> must be no longer than 255 characters.
    • TooManyTags
      • Must contain no more than 32 <tag>.


This library cannot parse sitemaps of any kind (yet! - pull requests welcome! See Feature Requests section below).


These examples should be exactly congruent to the examples found within the online documentation for each sitemap type.

URL Sitemap

cargo run --example generate_url_sitemap

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

Index Sitemap

cargo run --example generate_index_sitemap

<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

Image Sitemap

cargo run --example generate_image_sitemap

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">

Video Sitemap

cargo run --example generate_video_sitemap

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
      <video:title>Grilling steaks for summer</video:title>
      <video:description>Alkis shows you how to get perfectly done steaks every time</video:description>
      <video:restriction relationship="allow">IE GB US CA</video:restriction>
      <video:platform relationship="allow">web tv</video:platform>
      <video:uploader info="http://www.example.com/users/grillymcgrillerson">GrillyMcGrillserson</video:uploader>

News Sitemap

cargo run --example generate_news_sitemap

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
        <news:name>The Example Times</news:name>
      <news:title>Companies A, B in Merger Talks</news:title>

Alternative libraries

The rust-sitemap and sitewriter libraries are by far the best alternatives.

This pro/con list is accurate as of the most recent update to this document.



  • Supports URL, Index sitemaps
  • Supports reading files
  • Supports writing files


  • Doesn't support Image, Video, News sitemaps
  • Only supports some validations
  • Low struct/method documentation



  • Supports URL sitemaps
  • Supports writing files
  • Support builder pattern
  • uses quick-xml, so it should be quite fast
  • Some struct/method documentation


  • Doesn't support Index, Image, Video, News sitemaps
  • Doesn't support reading files
  • Zero data validations



  • Supports URL sitemaps
  • Supports reading files


  • Doesn't support Index, Image, Video, News sitemaps
  • Doesn't support writing files
  • Zero data validations
  • Low struct/method documentation



  • Supports URL sitemaps
  • Supports writing files


  • Doesn't support Index, Image, Video, News sitemaps
  • Doesn't support reading files
  • Zero data validations
  • Zero struct/method documentation



  • Semi-supports URL sitemaps
  • Supports writing files


  • Not a general use sitemap library
  • Doesn't support every possible tag of URL sitemaps
  • Doesn't support Index, Image, Video, News sitemaps
  • Doesn't support reading files
  • Zero data validations
  • Zero struct/method documentation


Project is under active maintenance - even if there are no recent commits! Please submit an issue / bug request if the library needs updating for any reason!

Built with: Rust 1.65

Feature Requests

Reading sitemap files (+ possible speed boost)

I would love to have this library use quick-xml instead of xml-builder.

The quick-xml library is built for speed and supports not only writing files, but reading them too. I haven't benchmarked xml-builder or its use in this library, so I cannot state the impact quick-xml will have there.

I originally went with xml-builder due to how extremely easy it is to learn and use. It is by far fast enough for my use-cases, so I didn't have to reach for anything else.

If you like what this library provides, but simply need the ability to parse sitemaps and could also use a speed boost - please consider pushing a pull request! (Preferably one that replaces xml-builder with quick-xml lol)

Codified country codes

In video sitemaps, there is a tag called <video: restriction> where the text is a space-delimited list of country codes in ISO 3166 format.

Currently, the country codes are typed-hinted as merely a HashSet<String>. It would be awesome if there was an enum/struct that codified each ISO 3166 country code as a separate entity, so this library could have extra assurances that each code was valid.

The isocountry-rs and rust_iso_3166 libraries looks promising.

This hasn't been prioritized yet as I am currently satisfied with HashSet<String> for my use cases. Pull requests are welcome!


  • make lint
    • Lints the codebase via cargo fmt.
  • make test
    • Tests the codebase via:
      • cargo fmt
      • cargo check
      • cargo clippy (with insanely strict defaults)
      • cargo test.


Made with 🤬 and 🥲 by Todd Everett Griffin.

sitemap-rs is open source under the MIT License.


~18K SLoC