#!/usr/bin/perl -w # processplist.pl # Author: Stephanie Troeth # Date created: 13 Feb 2003 # # This (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/*' ); my $mesgflag = 0; my $ogflag = 0; # we grab everything under dict, and then print the date when we see it. # then comes the awful part: # when we see a node (another word here for XML element) that # contains 'Message', we turn a flag on and skip the loop # so as to print the content of the next node. After we print # this second node, we turn the flag off again. # # We can only do this because we know we want the content of the # next node whenever we see a Message. # Then we do the same for 'Outgoing'. # This sucks! foreach my $n ($nodeset->get_nodelist) { if($n->getName() eq "date") { print "Date: ".$n->string_value()."\n"; } if($n->string_value() eq "Message") { $mesgflag++; next; } if($mesgflag) { print "Message: ".$n->string_value()."\n"; $mesgflag = 0; } if($n->string_value() eq "Outgoing") { $ogflag++; next; } if($ogflag) { print "Outgoing: ".$n->string_value()."\n"; $ogflag = 0; } }