5 releases (3 breaking)

0.4.1 Nov 3, 2020
0.4.0 Oct 2, 2019
0.3.0 Jul 10, 2018
0.2.0 Feb 4, 2018
0.1.0 Jan 3, 2017

#615 in Parser implementations

Download history 725/week @ 2024-03-14 934/week @ 2024-03-21 697/week @ 2024-03-28 589/week @ 2024-04-04 615/week @ 2024-04-11 467/week @ 2024-04-18 439/week @ 2024-04-25 562/week @ 2024-05-02 397/week @ 2024-05-09 466/week @ 2024-05-16 508/week @ 2024-05-23 562/week @ 2024-05-30 1837/week @ 2024-06-06 2250/week @ 2024-06-13 2730/week @ 2024-06-20 3288/week @ 2024-06-27

10,194 downloads per month
Used in 9 crates (7 directly)

MIT license

29KB
592 lines

sitemap, an Sitemap library for Rust

Chrono-utils on Travis CI Chrono-utils on crates.io

sitemap is an library for Rust programming language.

features

  • Streaming reading sitemap

Restrictions

  • no other encodings but UTF-8 are supported yet
  • validation is not supported

Building and using

sitemap uses Cargo, so just add a dependency section in your project's manifest:

[dependencies]
sitemap = "0.4"

Reading sitemap documents

sitemap::reader::SiteMapReader requires a Read instance to read from. When a proper stream-based encoding library is available, it is likely that sitemap will be switched to use whatever character stream structure this library would provide, but currently it is a Read.

Using SiteMapReader is very straightforward. Just provide a Read instance to obtain an iterator over events:

use sitemap::reader::{SiteMapReader,SiteMapEntity};
use std::fs::File;
fn main() {
    let mut urls = Vec::new();
    let mut sitemaps = Vec::new();
    let mut errors = Vec::new();
    let file = File::open("sitemap.xml").expect("Unable to open file.");
    let parser = SiteMapReader::new(file);
    for entity in parser {
        match entity {
            SiteMapEntity::Url(url_entry) => {
                urls.push(url_entry);
            },
            SiteMapEntity::SiteMap(sitemap_entry) => {
                sitemaps.push(sitemap_entry);
            },
            SiteMapEntity::Err(error) => {
                errors.push(error);
            },
        }
    }
    println!("urls = {:?}",urls);
    println!("sitemaps = {:?}",sitemaps);
    println!("errors = {:?}",errors);
}

Writng sitemap documents

use sitemap::writer::SiteMapWriter;
use sitemap::structs::UrlEntry;
use std::io::stdout;
fn main() {
    let mut output = stdout();
    let sitemap_writer = SiteMapWriter::new(&mut output);
    let mut urlwriter = sitemap_writer.start_urlset().expect("Unable to write urlset");
    urlwriter.url("http://github.com").expect("Unable to write url");
    urlwriter.url(UrlEntry::builder().loc("http://google.com")).expect("Unable to write url");
    urlwriter.url(UrlEntry::builder().loc("http://yandex.ru").build().unwrap()).expect("Unable to write url");
    urlwriter.end().expect("Unable to write close tags");
}

Roadmap

Highest priority first, approximately.

  1. Sitemap writer - done
  2. Sitemap validation

Known issues

All known issues are present on GitHub issue tracker: http://github.com/svmk/sitemap/issues. Feel free to post any found problems there.

License

This library is licensed under MIT license.

Dependencies

~2.5MB
~71K SLoC