# aidbrowser.pm package aidbrowser; use CGI; use XML::Twig; BEGIN { $allaids = "FindingAids/"; %FullNames = ( "UMASS" => "University of Massachussetts", "Smith" => "Smith College", "MtHolyoke" => "Mt. Holyoke College", "Amherst" => "Amherst College", "Hampshire" => "Hampshire College", "MortimerRareBookRoom" => "Mortimer Rare Book Room, Smith Col +lege", "SophiaSmithCollection" => "Sophia Smith Collection, Smith Col +lege" ); return bless( { }, shift); } sub printDirs() { my $rets; my $content; opendir(THISDIR, $allaids) or die ("Couldn't open finding aids for +browsing!"); my @dircontents = grep !/^\./, readdir THISDIR; closedir(THISDIR); foreach $content (@dircontents) { if(-e $allaids.$content && -d $allaids.$content) { if($FullNames{$content}) { $rets .= p(h2($FullNames{$content}),br,printAids($content +)); } } } return $rets; } sub printAids() { my $aiddir = shift; my $eadid,$eadtitle,$eadauthor,$eadlastchng; opendir(AIDDIR, $allaids.$aiddir."/"); my @dircontents = grep !/^\./, readdir AIDDIR; closedir(AIDDIR); my $rets; if(!@dircontents) { $rets .= em("No finding aids for this institution are available +at this time."); } else { foreach $aid (@dircontents) { if($aid =~ /(\w+).xml/) { $eadid = $1; $rets .= p($eadid); $eadtitle = getAidTitle($allaids.$aiddir."/".$aid); $rets .= p("Title is $eadtitle"); } } } return $rets; } sub getAidTitle() { my $file = shift; my $twig = new XML::Twig(); $twig->parsefile($file); $elt = $twig->get_xpath("//titleproper",0) or "No title"; $elt = $twig->get_xpath('/ead/eadheader/filedesc/titlestmt/titlepro +per',0) or "Invalid title"; $text = $elt->text; $text=~ s/(^\s*|\s*$)//g; return $text; } sub browsingMenu() { return h1("Select a finding aid to open"), printDirs(); } 1;
In reply to Twig.PM and parsing by Comrade
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |