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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.