Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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 lurking in the Monastery: (7)
As of 2015-10-08 18:55 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (223 votes), past polls