You do not have to forcearray everything, just those things that actually can be repeated. In this case you might be better off using a module that'll let you tweak the created datastructure. Something like:
use strict; use XML::Rules; use Data::Dumper; my $parser = XML::Rules->new( rules => { _default => 'content', Variable => sub {$_[1]->{Name} => $_[1]->{Value}}, IP => 'content array', 'VariableConfig,ServerConfig' => 'no content', Server => 'no content by Name', Config => 'pass no content', }, ); my $data = $parser->parse(\*DATA); print Dumper($data); my @FQDNs = map {$_->{FQDN}} values %{$data->{ServerConfig}}; print "@FQDNs"; __DATA__ <Config> <VariableConfig> <Variable> <Name>NAME</Name> <Value>somevalue</Value> </Variable> <Variable> <Name>NAME2</Name> <Value>somevalue blah</Value> </Variable> </VariableConfig> <ServerConfig> <Server> <Name>blue</Name> <IP>xxx.xxx.xxx.xx</IP> <IP>xxx.xxx.xxx.xx</IP> <FQDN>blue.some.domain</FQDN> </Server> <Server> <Name>black</Name> <IP>xxx.xxx.xxx.xx</IP> <IP>xxx.xxx.xxx.xx</IP> <FQDN>black.some.domain</FQDN> </Server> </ServerConfig> </Config>
In reply to Re: XML for Dummies
by Jenda
in thread XML for Dummies
by kevlinux
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |