Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
and the XML is along the lines of:use strict; use warnings; use XML::LibXML; my $searchterm="THESEUS"; my $file="c:\\webroot\\dream.xml"; #Get the XML file my $parse = XML::LibXML->new; my $doc = $parse->parse_file($file); my %releventlines; #Search through and find the correct field my %act; my $scene = $doc->findvalue('//PLAY//ACT//TITLE'); foreach $scene (keys %act) { my $item = $doc->findnodes('//PLAY//SCENE//SPEECH'); #Finding the speaker my $speech = $item->findvalue('SPEAKER'); next unless $speech eq $searchterm; my $text = $item->findvalue('LINE'); $text = $act{$scene}; } print $scene . "\n";
I'd be grateful for some advice as to where I've gone wrong (and I hope not too horrifically). Thanks.<PLAY> <ACT><TITLE>Act 1</TITLE></ACT> <SCENE><TITLE>SCENE I. Athens. The palace of THESEUS.</TITLE> <SPEECH> <SPEAKER>THESEUS</SPEAKER> <LINE>Now, fair Hippolyta, our nuptial hour</LINE> <LINE>Draws on apace; four happy days bring in</LINE> </SPEECH>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Setting up a hash in a linear search through XML
by Fletch (Bishop) on Oct 29, 2008 at 14:15 UTC | |
|
Re: Setting up a hash in a linear search through XML
by JadeNB (Chaplain) on Oct 29, 2008 at 23:05 UTC | |
by Anonymous Monk on Oct 30, 2008 at 09:45 UTC | |
by JadeNB (Chaplain) on Oct 30, 2008 at 19:09 UTC |