sub add_html { my $self = shift; my $ref = shift; # step over elements in fixed order my @elements; foreach my $key (qw(loc changefreq lastmod priority)){ if($key eq 'loc'){ if($ref->{loc}){ push(@elements, XML::Twig::Elt->new('loc', {}, $ref->{loc}) ); }else{ print "Error: 'loc' is a mandatory value and missing!\n" } }elsif($key eq 'priority'){ if($ref->{priority}){ push(@elements, XML::Twig::Elt->new('priority', {}, $ref->{priority}) ); }else{ print "Error: 'priority' is a mandatory value and missing!\n" } } } # wrap these sub-elements into an "url"-level my $elt = XML::Twig::Elt->new('url', {}, @elements); undef(@elements); # and add this url-sub-element nest to the xml-document $elt->paste(last_child => $self->{xml}); $self->{cnt}->{html}++; }