On 23 Oct 2007 at 14:21, Jenda Krynicky wrote:

> From: Rob Dixon <[EMAIL PROTECTED]>
> > I am unfamiliar with XML::Generator, but have experimented with it
> for
> > the purposes of your question and it seems to be essentially a
> translator
> > that will convert a Perl fragment into an XML fragment, and I can
> see no
> > way to modify existing XML. Because of this it seems extremely
> limited in
> > its application, as you would have to write
> > 
> >   my $xml = $gen->users(
> >     $gen->user({id => 10}, 'dermot'),
> >     $gen->user({id => 17}, 'joe'),
> >       :
> >   );
> > 
> > to create your desired output, which simply moves your problem to
> one of
> > how to generate the Perl from your data in the first place. If
> someone
> > on the list is familiar with XML::Generator then please correct me
> if I
> > am wrong.
> 
> It's just a matter of one map():
> 
> #!perl
> use XML::Generator;
> 
> $ref = {
>       'dermot' => '10',
>       'joe' => '17',
>       'rose' => '11',
>       'phil' => '13',
>       'brian' => '20',
>       'andy' => '15',
> };
> 
> my $gen = XML::Generator->new(':pretty');
> my $xml = $gen->users(
>      map { $gen->user({id => $ref->{$_}}, $_) } keys %{$ref}
> );
> 
> print $xml;
> __END__

Well that certainly does it. I could almost kick myself for not 
seeing it.

On a more general point I haven't found it easy to find modules that 
output XML or perhaps I should say, I didn't find the ones I did look 
at to be well documented in terms of examples or show the variety of 
different ways data structures can be represented in XML.

Excuse my whinge. Thanx to you both your help.
Dp.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to