#!/Perl

use XML::Simple;

my $file = 'files/camelids.xml';
my $xs1 = XML::Simple->new();

my $doc = $xs1->XMLin($file);
my $ky1;
my $tg;

print "Hello, World... loaded $file ...\n";
print "<html><head><title>$file</title></head>\n";
print "<body>\n";
print "<center><h1><b>$file</b></h1></center>\n";
print "<table border='1'>\n";

foreach my $key (keys (%{$doc->{species}})){

	print "<tr>\n";

	###print "<td>\n";
	print incolm($doc->{species}->{$key}->{'common-name'});
	###print "</td>\n";

	print incolm($key);

    ### print $doc->{species}->{$key}->{conservation}->final;
    ### print $doc->{species}->{$key}->{'conservation'}->final;
    print incolm($doc->{species}->{$key}->{'conservation'}->{'status'});

    ### print "\n";
    ### HASH %{$doc->{species}->{$key}->{'physical-characteristics'}}
    $tg = 'physical-characteristics';
#   foreach $ky1 (keys (%{$doc->{species}->{$key}->{'physical-characteristics'}}) ) {
#	   print $doc->{species}->{$key}->{'physical-characteristics'}->{$ky1} . " ";
#	   print $ky1 . "\n";
#   }

    foreach $ky1 (keys (%{$doc->{species}->{$key}->{$tg}}) ) {
	   print incolm(addbold($ky1) . ": " . $doc->{species}->{$key}->{$tg}->{$ky1});
	   ###print "\n";
   }

   $tg = 'natural-history';
   foreach $ky1 (keys (%{$doc->{species}->{$key}->{$tg}}) ) {
	   print incolm(addbold($ky1) . ": " . $doc->{species}->{$key}->{$tg}->{$ky1});
	   ### print "\n";
   }

	print "</tr>\n";
}

print "</table>\n";

print "</body>\n";
print "</html>\n";

sub addbold {
	my ($tx) = @_;
	return "<b>$tx</b>";
}

sub incolm {
	my ($tx) = @_;
	return "<td valign='top'>\n$tx\n</td>\n";
}
#eof

