How to parse the xml so that I can get a string list of class name = english, type = month and index = 3? Here is my code using twig:<root> <class name='music'> <record type='month' index='0'> # for the students of 1st mont +h. <string>sam1</string> <string>sam2</string> </record> <record type='month' index='1'> # for the students of 2nd mont +h. <string>mike1</string> <string>mike2</string> </record> </class> <class name='english'> <record type='week' index='2'> #for the students of 3rd week. <string>luke1</string> <string>luke2</string> </record> <record type='month' index='3'> # for the students of 3nd mont +h. <string>ben1</string> <string>ben2</string> </record> </class> </root>
use XML::Twig; #purpose: get the string of the related $class+$month+index sub parse_a_counter { my ($twig, $class) = @_; my $class_name = $class->{'att'}->{'name'}; my @report = $class->children('report [@type="month"]'); for my $report (@report){ my @string_list = $report->children_text('string'); } $class->flush; # free the memory of $counter } my $roots = { 'class[@name="english"]' => 1 }; my $handlers = { class => \&parse_a_counter }; my $twig = new XML::Twig(TwigRoots => $roots, TwigHandlers => $handlers); $twig->parsefile('class_report.xml');
20100713 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips
In reply to how to write this condition in XML:TWIG by lilili07
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |