in reply to XML::Twig help please
If you do not insist on using XML::Twig then with the use of a global variable:
and without any globals so that the parse() returns the created hash:use strict; use XML::Rules; my %data; my $parser = XML::Rules->new( stripspaces => 7, rules => { _default => '', url => 'content', urlInfo => sub { my ($tag,$attr,$context,$parents) = @_; $data{ $attr->{url} } = $parents->[-2]{name} }, } ); $parser->parse(\*DATA); use Data::Dumper; print Dumper(\%data); __DATA__ <authenticationReports> <generatedTime>Tue Sep 29 07:07:34 PDT 2009</generatedTime> ...
use strict; use XML::Rules; my $parser = XML::Rules->new( stripspaces => 7, rules => { _default => 'content', urlInfo => sub { return '@url' => $_[1]->{url}; }, application => sub { return 'url' => $_[1]->{url}; }, appDeploymentFile => sub { return '%urls' => { map {$_ => $_[1]->{name}} @{$_[1]->{url}} } }, authenticationReports => sub { return $_[1]->{urls} } } ); my $data = $parser->parse(\*DATA); use Data::Dumper; print Dumper($data); __DATA__ <authenticationReports> <generatedTime>Tue Sep 29 07:07:34 PDT 2009</generatedTime> ...
Jenda
Enoch was right!
Enjoy the last years of Rome.
|
|---|