perlvroom has asked for the wisdom of the Perl Monks concerning the following question:
Here is the code i have so far:<?xml version="1.0" encoding="utf-8"?> <Month> <Week> <Day day-of-week="Monday"> <Times> <Time start-time="01:00"/> </Times> </Day> <Day day-of-week="Tuesday"> <Times> <Time start-time="02:00"/> </Times> </Day> <Day day-of-week="Wednesday"> <Times> <Time start-time="03:00"/> </Times> </Day> <Day day-of-week="Thursday"> <Times> <Time start-time="04:00"/> </Times> </Day> <Day day-of-week="Friday"> <Times> <Time start-time="05:00"/> </Times> </Day> <Day day-of-week="Sunday"> <Times> <Time start-time="06:00"/> </Times> </Day> </Week> </Month>
I basically want to be able to get the "start-time" attribute for whichever day i specify.use XML::Twig; use strict; use warnings; my $twig=XML::Twig->new(); $twig->parsefile( 'CC.xml'); my $data = $twig->first_elt( 'Day' ); my $times = $twig->first_elt( 'Time' ); my $day = $data->att( 'day-of-week' ); my $time = $times->att('start-time'); if ($day='Tuesday') { print $time; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extracting XML data from a tree
by toolic (Bishop) on Jun 04, 2013 at 13:58 UTC | |
by perlvroom (Acolyte) on Jun 04, 2013 at 20:14 UTC | |
|
Re: Extracting XML data from a tree
by Neighbour (Friar) on Jun 04, 2013 at 14:22 UTC | |
by toolic (Bishop) on Jun 04, 2013 at 14:29 UTC | |
by Neighbour (Friar) on Jun 04, 2013 at 14:50 UTC | |
|
Re: Extracting XML data from a tree
by hdb (Monsignor) on Jun 04, 2013 at 14:43 UTC | |
by Jenda (Abbot) on Jun 05, 2013 at 08:30 UTC | |
by hdb (Monsignor) on Jun 05, 2013 at 08:51 UTC | |
|
Re: Extracting XML data from a tree
by choroba (Cardinal) on Jun 05, 2013 at 08:34 UTC |