Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: How to return two and more values by parsing XML with XML::Rules?

by vagabonding electron (Chaplain)
on Nov 06, 2012 at 14:31 UTC ( #1002483=note: print w/replies, xml ) Need Help??

in reply to How to return two and more values by parsing XML with XML::Rules?

After some thoughts and readings I was finally able to produce the desired output with XML::Rules.
#!/usr/bin/perl use strict; use warnings; use XML::Rules; use YAML::XS; my $parser = XML::Rules->new( rules => { 'Capacities_Outpatient_Clinic, Other, Outpatient_Clinic, Outpatient_Clinic_Special, Outpatient_Services' => 'no content', 'Capacities_Outpatient_Clinic_Special' => 'pass', 'AM_Key, AM_Other_Key, AM_Special_Key, Description, Explanations, LK_Key, Type, VA_VU_Key_Outpatient_Clinic, VA_VU_Other_Key_Outpatient_Clinic' => 'content', 'Care_Point' => 'as array no content', 'Capacity' => sub {$_[1]->{LK_Key} => 1}, 'Outpatient_Service' => sub { if (exists $_[1]->{Outpatient_Clinic}) { if ( exists $_[1]->{Outpatient_Clinic}->{Other} ) { return $_[1]->{Outpatient_Clinic}->{Description} => 1 } else { return $_[1]->{Outpatient_Clinic}->{AM_Key} => 1 } } elsif ( exists $_[1]->{Outpatient_Clinic_Special} ) { my $h; for ( keys %{ $_[1]->{Outpatient_Clinic_Special} } ) { $h->{$_} = 1 if /LK\d*/; } return %$h; } else { } }, } ); my $data = $parser->parsefile(shift); print Dump $data;
which prints
--- Outpatient_Services: AM01: 1 AM02: 1 AM04: 1 Description of the Outpatient Clinic: 1 LK01: 1 LK02: 1
from the posted xml fragment.
What I still do not know is whether this is a proper use of the module or a side way.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002483]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2018-05-24 14:50 GMT
Find Nodes?
    Voting Booth?