matrixmadhan has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

Am looking for hints for a problem with XML generation, I searched internet, perlmonks but could not find an answer that I am looking for

Here is the sample code

use strict; use XML::Generator; my $attribute_name = 'book'; my $value = 'value'; my $attribute_value = 'Camel book'; my $xml_handle = XML::Generator->new( pretty => 4 ); print $xml_handle->$attribute_name($xml_handle->$value($attribute_ +value)); print "\n"; exit(0);
And this will give an output of the form

<book>
<value>Camel book</value>
</book>

But what am interested to know is, how to display multiple values to an XML element something like

<book>
<value>Camel book</value>
<value>Complete Reference - Perl</value>
<value>Black Perl</value>
</book>

I tried using an array ref something like
print $xml_handle->$attribute_name($xml_handle->$value(@$attribute_val +ue));

but that didn't work

I don't find a relavant example in CPAN as well.

Any pointers would be really helpful to me, thanks

Replies are listed 'Best First'.
Re: Multiple value tags for xml element using XML::Generator
by ikegami (Patriarch) on Nov 26, 2008 at 07:05 UTC
    print $xml_handle->book( map { $xml_handle->value($_) } @values );
      Many thanks for the reply
      This is what I was looking for.
      I need to revise my basics on map
      thanks again

        map isn't technically needed. It was just convenient.

        my @value_eles; for (@values) { push @value_eles, $xml_handle->value($_); } print $xml_handle->book(@value_eles);