#!/usr/bin/perl -w # processplist_2.pl # Author: Stephanie Troeth # Date created: 13 Feb 2003 # # This (yet another not very good) perl script was written to # process a file of the format in 'extract.xml'. # (see http://unadorned.org/processplist/extract.xml) # We want an output of: # Date: (date) # Message: (content of following Message) # Outgoing (content of following Outgoing) # use XML::XPath; use XML::XPath::XMLParser; my $xp = XML::XPath->new(filename => "file.xml"); my $nodeset = $xp->find('/plist/array/dict/*' ); # we grab all elements under 'dict' and stick it in an array my @array = $nodeset->get_nodelist; for($i=0; $i <=$#array; $i++) { # we print the value of 'date' if we encounter the element print "Date: ".$array[$i]->string_value()."\n" if($array[$i]->getName() eq "date"); # we print the value of the _next_ element along # if we encounter an element which contains 'Message' print "Message: ".$array[$i+1]->string_value()."\n" if($array[$i]->string_value() eq "Message"); # we print the value of the _next_ element along # if we encounter an element which contains 'Outgoing' print "Outgoing: ".$array[$i+1]->string_value()."\n" if($array[$i]->string_value() eq "Outgoing"); }