Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Relating data parsed with XMLSimple

by Jenda (Abbot)
on Mar 30, 2010 at 11:42 UTC ( #831821=note: print w/ replies, xml ) Need Help??

in reply to Relating data parsed with XMLSimple

The XML is not very well designed ... depending on the order of tags in a data oriented XML is a bad idea. Anyway ... do you like this output better?:

use strict; use XML::Rules; use Data::Dumper; my $data=q( <Data> <Name><Lname>xyz</Lname><Fname>abcd</Fname></Name> <Phone><Mobile>123456789</Mobile><Home>55656556</Home></Phone> <Phone><Mobile>123456789</Mobile><Home>55656556</Home></Phone> <Name><Lname>UTV</Lname><Fname>EFGH</Fname></Name> <Phone><Mobile>123456789</Mobile><Home>55656556</Home></Phone> </Data>); my $parser = XML::Rules->new( stripspaces => 7, rules => { _default => 'content', Name => 'as array no content', Phone => sub { #return; my ($tag,$attr,$context,$parents) = @_; if (! $parents->[-1]{Name}) { warn "<Phone> before <Name>!\n"; } else { push @{$parents->[-1]{Name}[-1]{Phones}}, $attr; } return }, Data => sub {$_[1]->{Name}}, } ); my $ref = $parser->parse($data); print Dumper($ref);

Enoch was right!
Enjoy the last years of Rome.

Comment on Re: Relating data parsed with XMLSimple
Download Code
Replies are listed 'Best First'.
Re^2: Relating data parsed with XMLSimple
by mohan2monks (Beadle) on Mar 30, 2010 at 12:00 UTC

    Yes sir this output definately looks better but will have to install this module and check if this is possible to include in the existing code.

    Thank you very much

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://831821]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2015-11-27 06:17 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (719 votes), past polls