Parser

NAME

Sitemap::Parser - Parse existing XML sitemaps

SYNOPSIS


use Sitemap::Parser;

# Parse from file
my @items = Sitemap::Parser.parse-xml-file('sitemap.xml');
for @items -> $item {
    say $item.url, ' ', $item.lastmod // 'no date';
}

# Parse from string
my $xml = q:to/XML/;
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://example.com/page</loc>
    <lastmod>2024-01-01</lastmod>
  </url>
</urlset>
XML

my @items2 = Sitemap::Parser.parse-xml-string($xml);

# Parse sitemap index
my @sitemaps = Sitemap::Parser.parse-xml-index-file('sitemap_index.xml');

This module parses raw XML sitemaps only. For automatic format detection and loose formats (RSS, Atom, HTML, TXT) use the Sitemap::InputParser module.

METHODS

parse-xml-file(IO::Path $file --> List)

Parse an XML sitemap file and return a list of SitemapItem objects.

parse-xml-string(Str $xml --> List)

Parse an XML sitemap string and return a list of SitemapItem objects.

parse-xml-index-file(IO::Path $file --> List)

Parse a sitemap index file and return a list of sitemap URLs.

parse-xml-index-string(Str $xml --> List)

Parse a sitemap index XML string and return a list of sitemap URLs.

parse-xml-files(*@files, :$parallel = True)

Parse multiple sitemap files in parallel (or sequentially if $parallel is False). Returns a ParseResult with .items (list of Sitemap::Item objects) and .errors (list of failures). Also supports hash-style access: $result<items>, $result<errors>.

parse-xml-url-recursive(Str $url, :$max-depth, :$verify-ssl)

Recursively parse a sitemap URL. If the URL is a sitemap index, all child sitemaps are fetched and parsed. Returns a ParseResult with: .items (all parsed items), .errors, .sitemaps (all sitemap URLs found), .urls-parsed (count of URLs processed). Also supports hash-style access: $result<items>, $result<errors>, etc.

parse-xml-file-recursive(IO::Path $file, :$max-depth)

Recursively parse a local sitemap index file and all referenced child sitemaps. Returns a ParseResult with: .items, .errors, .sitemaps, .files-parsed (count of files processed). Also supports hash-style access: $result<items>, $result<errors>, etc.

Sitemap v0.0.1

Sitemap generator for Raku

Authors

  • Sasha Abbott

License

CC0-1.0

Dependencies

Cro::HTTP:auth<zef:cro>:api<0>URI:auth<zef:raku-community-modules>LibXML:auth<zef:dwarring>LibXML::Writer:auth<zef:dwarring>Compress::ZlibJSON::Fast:auth<zef:timo>YAMLish:auth<zef:leont>DateTime::Format:auth<zef:raku-community-modules>Syndicate:auth<zef:sasha>

Test Dependencies

Provides

  • Sitemap
  • Sitemap::Builder
  • Sitemap::Config
  • Sitemap::Crawler
  • Sitemap::DirScanner
  • Sitemap::Extraction
  • Sitemap::Fetcher
  • Sitemap::Format::Atom
  • Sitemap::Format::FeedBuilder
  • Sitemap::Format::HTML
  • Sitemap::Format::MRSS
  • Sitemap::Format::RSS
  • Sitemap::Format::TXT
  • Sitemap::Grammar::LinkExtract
  • Sitemap::Grammar::RobotsTxt
  • Sitemap::Grammar::SitemapSniff
  • Sitemap::InputParser
  • Sitemap::Item
  • Sitemap::JsonLd
  • Sitemap::Parser
  • Sitemap::SiteTree
  • Sitemap::Subscribable

The Camelia image is copyright 2009 by Larry Wall. "Raku" is a trademark of the Yet Another Society. All rights reserved.

Built with Podlite β€” the markup and publishing tools behind this site.