Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Generating elements with attributes and contents using XML::Smart

by leriksen (Curate)
on Aug 19, 2004 at 05:03 UTC ( [id://384184]=note: print w/replies, xml ) Need Help??


in reply to Generating elements with attributes and contents using XML::Smart

I dont know the exact form of the (presumably) hash you are getting back form the DB, but here is one way for a fairly flat hash

#!/usr/bin/perl -w use strict; use Data::Dumper; use XML::Simple qw(:strict); my $data = { phone => '555-1234', type => 'home' }; print STDERR XML::Simple->new(KeyAttr => {phone => 'type'}, RootName => 'phone', XMLDecl => 1, ContentKey => 'phone', )->XMLout($data);
output

/usr/bin/perl -w "/home/le6303/src/perl/phone.pl" <?xml version='1.0' standalone='yes'?> <phone type="home">555-1234</phone>
Update : changed the KeyAttr to the more preferred hash form

use brain;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-18 14:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found