1
2
3
4
5
6
7
8
9
<urlset>
(
<url>
<loc>url</loc>
<changefreq>freq</changefreq>
<priority>num</priority>
</url>
)+
</urlset>
urlset => [{url => {loc => 'loc', changefreq => 'freq', ...}}]
1
2
3
4
5
<opt>
<urlset>
<anon name="url" changefreq="dreq" loc="loc" priority="num" />
</urlset>
</opt>
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
32
33
34
35
36
37
38
39
#!/usr/bin/perl -w
use strict;
use warnings;
use Data::Dumper qw/Dumper/;
use Perl6::Say;
use FindBin qw/$Bin/;
use XML::Simple;
my @data = (
{
url => [
{
loc => 'loc',
changefreq => 'changefreq',
priority => 'priority',
},
{
loc => 'loc2',
changefreq => 'changefreq2',
priority => 'priority2',
},
],
},
);
my $xs = XML::Simple->new(
ForceArray => 1,
XMLDecl => 1,
NoAttr => 1,
KeepRoot => 1,
);
my $xml = $xs->XMLout(
{urlset => \@data},
#OutputFile => $outfile,
);
print Dumper $xml;