WWW::Sitemap::XML - XML Sitemap protocol
version 1.103500
use WWW::Sitemap::XML; my $map = WWW::Sitemap::XML->new(); # add new url $map->add( 'http://mywebsite.com/' ); # or $map->add( loc => 'http://mywebsite.com/', lastmod => '2010-11-22', changefreq => 'monthly', priority => 1.0, ); # or $map->add( WWW::Sitemap::XML::URL->new( loc => 'http://mywebsite.com/', lastmod => '2010-11-22', changefreq => 'monthly', priority => 1.0, ) ); # read URLs from existing sitemap.xml file my @urls = $map->read( 'sitemap.xml' ); # load urls from existing sitemap.xml file $map->load( 'sitemap.xml' ); # get XML::LibXML object my $xml = $map->as_xml; print $xml->toString(1); # write to file $map->write( 'sitemap.xml', my $pretty_print = 1 ); # write compressed $map->write( 'sitemap.xml.gz' );
Read and write sitemap xml files as defined at http://www.sitemaps.org/.
$map->add( WWW::Sitemap::XML::URL->new( loc => 'http://mywebsite.com/', lastmod => '2010-11-22', changefreq => 'monthly', priority => 1.0, ) );
Add the $url object representing single page in the sitemap.
$url
Accepts blessed objects implementing WWW::Sitemap::XML::URL::Interface.
Otherwise the arguments %attrs are passed as-is to create new WWW::Sitemap::XML::URL object.
%attrs
$map->add( loc => 'http://mywebsite.com/', lastmod => '2010-11-22', changefreq => 'monthly', priority => 1.0, ); # single url argument $map->add( 'http://mywebsite.com/' ); # is same as $map->add( loc => 'http://mywebsite.com/' );
Performs basic validation of urls added:
maximum of 50 000 urls in single sitemap
URL no longer then 2048 characters
all URLs should use the same protocol and reside on same host
my @urls = $map->urls;
Returns a list of all URL objects added to sitemap.
$map->load( location => $sitemap_file );
It is a shortcut for:
$map->add($_) for $map->read( location => $sitemap_file );
Please see "read" for details.
# file or url to sitemap my @urls = $map->read( location => $file_or_url ); # file handle my @urls = $map->read( IO => $fh ); # xml string my @urls = $map->read( string => $xml );
Read the sitemap from file, URL, open file handle or string and return the list of WWW::Sitemap::XML::URL objects representing <url> elements.
<url>
# write to file $map->write( 'sitemap.xml', my $pretty_print = 1); # or my $fh = IO::File->new(); $fh->open('sitemap.xml', 'w'); $map->write( $fh, my $pretty_print = 1); $cfh->close; # write compressed $map->write( 'sitemap.xml.gz' );
Write XML sitemap to $file - a file name or IO::Handle object.
$file
If file names ends in .gz then the output file will be compressed by setting compression on xml object - please note that it requires libxml2 to be compiled with zlib support.
.gz
Optional $format is passed to toFH or toFile methods (depending on the type of $file, respectively for file handle and file name) as described in XML::LibXML.
$format
toFH
toFile
my $xml = $map->as_xml; # pretty print print $xml->toString(1); # write compressed $xml->setCompression(8); $xml->toFile( 'sitemap.xml.gz' );
Returns XML::LibXML::Document object representing the sitemap in XML format.
The <url> elements are built by calling as_xml on all URL objects added into sitemap.
WWW::SitemapIndex::XML
http://www.sitemaps.org/
Search::Sitemap
Alex J. G. Burzyński <ajgb@cpan.org>
This software is copyright (c) 2010 by Alex J. G. Burzyński <ajgb@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install WWW::Sitemap::XML, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WWW::Sitemap::XML
CPAN shell
perl -MCPAN -e shell install WWW::Sitemap::XML
For more information on module installation, please visit the detailed CPAN module installation guide.