#/* Du format 1 au format 2 des Noms-Notes, pour comparaison */

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

sub transformer ($) { #Document -> Document
	my ($doc) = @_;
	my $depart = $doc->getDocumentElement();
	my $rac = $depart->getNodeName();
	
	my $res = XML::DOM::Document->new();
	my $r_rac = $res->createElement($rac);
	$res->appendChild($r_rac);
	
	my @les_eleves = $depart->getElementsByTagName("eleve");
	foreach my $l_eleve ( @les_eleves  ){ # foreach marche avec NodeList !
	
	#lecture
		my $le_nom = $l_eleve->getAttribute("nom");
		my $la_note = $l_eleve->getAttribute("note");
	#construction
		my $r_eleve = $res->createElement("eleve");
		$r_rac->appendChild($r_eleve);
		my $r_nom = $res->createElement("nom");
		$r_eleve->appendChild($r_nom);
		$r_nom->appendChild($res->createTextNode($le_nom));
		my $r_note = $res->createElement("note");
		$r_eleve->appendChild($r_note);
		$r_note->appendChild($res->createTextNode($la_note));
	}
			
	return $res;
}# transformer

sub UnVersDeux($$){
	my ($fichIn, $fichOut) = @_;
	my $parseur = XML::DOM::Parser->new();
	my $doc = $parseur->parsefile($fichIn);
	open(SORTIE, ">$fichOut");
	
	my $res = transformer($doc);
	print(SORTIE $res->toString());
	
}#UnVersDeux

UnVersDeux($ARGV[0], $ARGV[1]);