Re: Help generating XML output
- From: dermot@xxxxxxxxxxxxxxxx (Beginner)
- Date: Tue, 23 Oct 2007 13:39:26 +0100
On 23 Oct 2007 at 14:21, Jenda Krynicky wrote:
From: Rob Dixon <rob.dixon@xxxxxxx>
I am unfamiliar with XML::Generator, but have experimented with itfor
the purposes of your question and it seems to be essentially atranslator
that will convert a Perl fragment into an XML fragment, and I cansee no
way to modify existing XML. Because of this it seems extremelylimited in
its application, as you would have to writeone of
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
how to generate the Perl from your data in the first place. Ifsomeone
on the list is familiar with XML::Generator then please correct meif 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.
.
- Follow-Ups:
- Re: Help generating XML output
- From: Jenda Krynicky
- Re: Help generating XML output
- References:
- Help generating XML output
- From: Beginner
- Re: Help generating XML output
- From: Rob Dixon
- Re: Help generating XML output
- From: Jenda Krynicky
- Help generating XML output
- Prev by Date: Re: How do I properly use global variables?
- Next by Date: Re: Absolute noobie question regarding opening files on Windows platform
- Previous by thread: Re: Help generating XML output
- Next by thread: Re: Help generating XML output
- Index(es):
Relevant Pages
|