Re: Help generating XML output



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 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.

.



Relevant Pages

  • Re: probably a simple question (I hope)
    ... That does match the structure of the XML I desire. ... However I am still unable to achieve the desired output for some reason. ... My schema is nested. ...
    (microsoft.public.dotnet.general)
  • Re: Help generating XML output
    ... If I use this loop to generate the output with XML::Generator I only get the last user in the XML ... But I can't determine how to use ValueAttr to suit my needs as the keys/values are not know. ... that will convert a Perl fragment into an XML fragment, ... to create your desired output, which simply moves your problem to one of ...
    (perl.beginners)
  • Re: XmlTextReader and XmlTextWriter
    ... After spending a few hours searching for the answer and writing this, ... > The XML is XHTML. ... > the desired output ... > foreach (String attributeName in attributes) ...
    (microsoft.public.dotnet.xml)
  • XmlTextReader and XmlTextWriter
    ... Hi - I am trying to read an XML file using XmlTextReader and write it ... The XML is XHTML. ... the desired output ...
    (microsoft.public.dotnet.xml)
  • need XML schema to store infomation in a language neutral format
    ... I am building a language translator, ... source languages to a language neutral format in XML. ...
    (comp.text.xml)