1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/perl
use strict;
use warnings;
use XML::Smart;
my $sitemap = XML::Smart->new();
$sitemap=$sitemap->{'urlset'};
push(@{$sitemap->{'url'}},
{loc => "http://www.example.com/page1.html", lastmod => "2013-11-20"});
push(@{$sitemap->{'url'}},
{loc => "http://www.example.com/page2.html", lastmod => "2013-11-21"});
print $sitemap->data(), "\n";
1
2
3
4
5
[...]
<urlset>
<url lastmod="2013-11-20" loc="http://www.example.com/page1.html"/>
<url lastmod="2013-11-21" loc="http://www.example.com/page2.html"/>
</urlset>
1
2
3
4
5
6
7
8
9
10
11
[...]
<urlset>
<url>
<loc>http://www.example.com/page1.html</loc>
<lastmod>2013-11-20</lastmod>
</url>
<url>
<loc>http://www.example.com/page2.html</loc>
<lastmod>2013-11-21</lastmod>
</url>
</urlset>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#! /usr/bin/env perl use strict; use warnings; use XML::Quick; use XML::Smart; # Bereite Datenstruktur vor my %hash = ( urlset => { url => [ { loc => "http://www.example.com/page1.html", lastmod => "2013-11-20", }, { loc => "http://www.example.com/page2.html", lastmod => "2013-11-21", }, ], }, ); # neue Sitemap auf Basis der Datenstruktur; xml() stammt von XML::Quick; siehe perldoc XML::Quick my $sitemap = XML::Smart->new(xml(\%hash)); # und raus damit: print $sitemap->data(), "\n"; __END__
1
2
3
4
5
6
7
8
9
10
11
12
<?xml version="1.0" encoding="UTF-8" ?>
<?meta name="GENERATOR" content="XML::Smart/1.78 Perl/5.018001 [linux]" ?>
<urlset>
<url>
<lastmod>2013-11-20</lastmod>
<loc>http://www.example.com/page1.html</loc>
</url>
<url>
<loc>http://www.example.com/page2.html</loc>
<lastmod>2013-11-21</lastmod>
</url>
</urlset>