foreach my $k (keys %{$ref}) { $xml = $gen->users( # $xml gets over written with every new key.... So instead of doing that I would try $xml .= (appending) $gen->username({ id => $ref->{$k}},$k), ); }
On 10/23/07, Beginner <[EMAIL PROTECTED]> wrote: > > Hi, > > I have been trying to output XML that looks like this: > > <users> > <username id="10">dermot</username> > <username id="17">joe</username> > ... > </users> > > I have tried XML::Simple and XML::Generator but keep hitting the same > problem when it comes to separating the id attribute and the value > from my hash reference. > > $VAR1 = { > 'dermot' => '10', > 'joe' => '17', > 'rose' => '11', > 'phil' => '13', > 'brian' => '20', > 'andy' => '15', > }; > > If I use this loop to generate the output with XML::Generator I only > get the last user in the XML > > my $xml; > my $gen = XML::Generator->new(':pretty'); > foreach my $k (keys %{$ref}) { > $xml = $gen->users( > $gen->username({ id => $ref->{$k}},$k), > ); > } > print $xml; > > <username id="15">andy</username> > > With XML::Simple I considered using this: > > my $xml = XMLout($ref, RootName => 'users', ValueAttr => { '??' => > '??'} > > But I can't determine how to use ValueAttr to suit my needs as the > keys/values are not know. > > I think XML::Generator would suit me best but I can't see can append > data to $xml. Can anyone offer any advice? > > TIA, > Dp. > > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > http://learn.perl.org/ > > >