#Imprimer Neruda bien structuré

use strict;
use warnings;
use XML::DOM;

# La structure

sub printPoema($){ #arg. Element "poema"
	my ($poema) = @_;
	
	my ($titre) = $poema->getElementsByTagName("t\x{00ED}tulo");
	printTitre($titre->getFirstChild()->getData());
	
	my @estrofas =  $poema->getElementsByTagName("estrofa");
	foreach my $estrofa ( @estrofas ){
		printEstrofa($estrofa);
		printFinStrofa();
	}
}#printPoema

sub printEstrofa($){ #arg. Element "estrofa"
	my ($str) = @_;
	
	my @versos = $str->getElementsByTagName("verso");
	foreach my $verso ( @versos ){
		print($verso->getFirstChild()->getData());
		printFinVerso();
	}
}#printEstrofa

# Choix typographiques

sub printTitre($){ # arg. chaîne
	my ($chn) = @_;
	
	print("<h3>$chn</h3>\n");
}

sub printFinVerso(){
	print("<br />\n");
}

sub printFinStrofa(){
	print("<hr />\n");
}

# Exécution

sub lecture ($){# nom de fichier
	my ($fichIn) = @_;
	my $parseur = XML::DOM::Parser->new();
	my $doc = $parseur->parsefile($fichIn);
	
	binmode(STDOUT, ":utf8");
	print('<html><head><meta content="text/html; charset=UTF-8" http-equiv="content-type" />
<title>FromXML</title></head><body>');
	printPoema ($doc->getDocumentElement());
	print("</body></html>\n");
}#lecture

lecture($ARGV[0]);