# L'exemple du cours DOM-1 // 2ème version

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

binmode(STDOUT, ":utf8");

sub nonVide($){ # arg. Node
	my ($node) = @_;
	return ($node->getNodeName() ne '#text') || ($node->getData() !~ /^\s*$/);
}

my $parseur = XML::DOM::Parser->new();
my $doc = $parseur->parsefile("Voiture.xml");

my $voiture = $doc->getDocumentElement();
my $nom = $voiture->getTagName();
print("$nom\n");

my $marque = $voiture->getAttribute("marque"); 
my $modele = $voiture->getAttribute("mod\x{00E8}le");
print("$marque $modele\n");

my @cmt = $voiture->getChildNodes();
foreach my $enf ( @cmt ){
   if( nonVide($enf) ){
   		print ($enf->getTagName());
   		print(" ");
   	}
}
print("\n");

my ($capot) = $voiture->getElementsByTagName("Capot");

my $chn = $capot->getFirstChild()->getData(); # abrégeons !
print("Capot : $chn\n");



