Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Nested XML Question

by hdb (Parson)
on Jun 25, 2013 at 06:04 UTC ( #1040533=note: print w/ replies, xml ) Need Help??


in reply to Nested XML Question

With XML::Simple you have to traverse the structure yourself. Recursion is what you need then.

use strict; use warnings; use XML::Simple; sub findranges { my $text = shift; my $href = shift; print "$text\n"; $text .= ".".$$href{name} if exists $$href{name}; if( exists $$href{"host-group"} ) { for my $name (keys %{ $$href{"host-group"} } ) { findranges( "$text.$name", $$href{"host-group" +}{$name} ); } } if( exists $$href{"ip-address-ranges"} ) { if( ref( $$href{"ip-address-ranges"} ) ) { print "$text\t$_\n" for @{ $$href{"ip-address- +ranges"} }; } else { print "$text\t".$$href{"ip-address-ranges"}."\ +n"; } } } my $xml = XMLin( 'hosts.xml' ); findranges( "", $$xml{'host-group'} );


Comment on Re: Nested XML Question
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (16)
As of 2014-07-24 13:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (160 votes), past polls