#!/Perl

use Data::Dumper;
use XML::Simple;
my $outfil = shift || 'tempxout.htm';
my ($OF);

my $file = 'position.xml';
my $ky1;
my $tg;
my $k;
my $k2;
my $k3;
my $add1 = 0;
my $html;
my $addr;

##use Socket;
###$name = 'geoffmclane.com';
##$name = 'home.exetel.com.au';
##@addresses = gethostbyname($name)   or die "Can't resolve $name: $!\n";
##@addresses = map { inet_ntoa($_) } @addresses[4 .. $#addresses];
##foreach $k (@addresses) { print "$k\n"; }
##print Dumper(@addresses);

open $OF, ">$outfil" or die "Can not create $outfil!\n";


my $xs1 = XML::Simple->new();
##my $xsl = new XML::Simple(ForceArray => 1, KeepRoot => 1);
#my $xs1 = XML::Simple->new(ForceArray => 1, KeepRoot => 1);
my $doc = $xs1->XMLin($file);
print "Hello, World... loaded $file ...\n";

prt( "<html><head><title>$file</title></head>\n" );
prt( "<body>\n" );
prt( "<center><h1><b>$file</b></h1></center>\n" );
prt( "<table border='1'>\n" );

my $tree1 = 'config';
my $tree2 = 'position';
$k = 'latitude';
$k2 = 'longitude';
my @arr = $doc->{$tree1}->{$tree2};
##prt( incolm("[" . $doc->{$tree1}->{$tree2} . "]\n") );
$html ='';
foreach $k (@arr) {
	if ($html ne '') {
		$html += '|';
	}
	$html += $k
}
prt( incolm("[$html]\n") );

foreach my $key (keys (%{$doc->{$tree1}->{$tree2}})){
##foreach my $key (keys (%{$doc->{position}})){
	prt( addrow( incolm(addbold($key)) ) );
}

prt( "</table>\n" );

prt( "<pre>\n" );
prt( Dumper($doc) );
prt( "</pre>\n" );
prt( addpre("[" . Dumper($doc->{$tree1}->{$tree2}) . "]\n") );

##foreach $addr (@addresses) {
##	my $nm2 = gethostbyaddr(inet_aton($addr), AF_INET)
##            or die "Can't resolve $address: $!\n";
##	prt("$addr - $name - $nm2\n");
##}

prt( "</body>\n" );
prt( "</html>\n" );

close $OF;
system $outfil;

sub addpre {
	my ($tx) = @_;
	return "<pre>\n$tx\n</pre>\n";
}

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

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

sub addrow {
	my ($tx) = @_;
	return "<tr>\n$tx\n</tr>\n";
}

sub prt {
	###tolog (@_);
	print @_;
	print $OF @_;
}

#eof

