Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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);

Jenda
Enoch was right!
Enjoy the last years of Rome.


Comment on Re: Relating data parsed with XMLSimple
Download Code
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2014-09-21 03:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (166 votes), past polls