#!/usr/bin/perl -w -T use strict; use CGI; use Data::Dumper; use XML::Parser; my $xmlpg = new CGI; my $file = $xmlpg->param("INPUT"); my ($ID,$from, $to); my $p =new XML::Parser(Style=>'Tree'); my $doc = $p->parsefile("$file"); #print Dumper($doc); my $level =0; process_node(@$doc); sub process_node { my ($type, $content) = @_; if ($type eq 'id') { $ID = trim($content->[2]); } elsif ($type eq 'from') { $from = trim($content->[2]); } elsif ($type eq 'to') { $to = trim($content->[2]); } if ($type) { while (my @node = splice @$content, 1, 2) { process_node(@node) } } } sub trim { local $_ = shift; s/\n/ /g; s/^\s+//; s/\s+$//; return $_; } print $xmlpg ->header, $xmlpg->start_html( -title => "XML File", -BGCOLOR => 'white', -LINk => 'red' ), $xmlpg->h1("Looking at $ID which starts at $from and finishes at $to");