in reply to XMLout and keys/attributes
You are probably best off using something like XML::LibXML. XML::Simple is mostly for people who just want to treat XML as if it were a big hash structure, and don't care about the XML elements, attributes, text nodes, etc.
use Scalar::Util qw[blessed]; use XML::LibXML; use XML::LibXML::PrettyPrint qw[print_xml]; sub element { my $elem = XML::LibXML::Element->new(shift); foreach my $child (@_) { if (blessed $child and $child->isa('XML::LibXML::Node')) { $elem->appendChild($child); } elsif (ref $child eq 'HASH') { $elem->{$_} = $child->{$_} foreach keys %$child; } else { $elem->appendText($child); } } return $elem; } print_xml element opt => ( element key0 => ( element devices => ( element dev0 => ( element(param => { id => "name"}, "joe"), element(param => { id => "type"}, "user"), ), ), ), );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: XMLout and keys/attributes
by atreyu (Sexton) on May 09, 2012 at 15:32 UTC |