Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Nested XML Question

by tobyink (Abbot)
on Jun 25, 2013 at 09:26 UTC ( #1040567=note: print w/ replies, xml ) Need Help??


in reply to Nested XML Question

This seems to do the job:

#!/usr/bin/env perl use strict; use warnings; use XML::LibXML 2; my $xml = "XML::LibXML"->load_xml(location => "input.xml"); for my $hg ($xml->findnodes('//host-group')) { my $path = join ".", $hg->findnodes('ancestor-or-self::host-group' +)->map(sub { $_->{name} }); my @ips = $hg->findnodes('ip-address-ranges')->map(sub { split /\ +s*,\s*/, $_->textContent }); print "$path\t$_\n" for @ips; }
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name


Comment on Re: Nested XML Question
Download Code
Re^2: Nested XML Question
by zelet (Initiate) on Jun 25, 2013 at 13:29 UTC

    That's perfect and solved my issue! Thank you!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-09-20 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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











    Results (163 votes), past polls