Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Outputting a hash as XML

by mirod (Canon)
on Mar 15, 2005 at 10:38 UTC ( [id://439578]=note: print w/replies, xml ) Need Help??


in reply to Outputting a hash as XML

First, there is probably a way to get XML::Simple to output what you want, but anyway, here is the easiest way I found with XML::Twig: the first new creates the root element, then the map creates its children, each created by the second new.

#!/usr/bin/perl -w use strict; use XML::Twig; my %hash= ( name => 'bob', value1 => 'blah', value2 => 'blah2', ); XML::Twig::Elt->new( newPhone => map { XML::Twig::Elt->new( $_ => $has +h{$_}) } sort keys %hash) ->print( 'indented' );

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://439578]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-20 02:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found