I am not using XMLin for anything.
Then I would ditch XMLout ASAP :) seriously
The way I use XML::Simple, is start with XML I want, then use XMLin to get data I want, then XMLout to get back xml I started with
If XMLin can't be made into data structure you want, then XMLout can't be made into xml you want
All that massaging of $userref you do is busywork :)
So with XML::Rules ( XML::Simple on steriods :) steroids) I might write
#!/usr/bin/perl -- use strict; use warnings; use XML::Rules; use Data::Dump qw/ dd /; my $wanted = <<'__XML__'; <?xml version="1.0" encoding="utf-8"?> <opt> <key0> <devices> <dev0> <param id="name">joe</param> <param id="type">user</param> </dev0> </devices> </key0> <key1> <devices> <dev0> <param id="name">mary</param> <param id="type">user</param> </dev0> </devices> </key1> </opt> __XML__ use XML::Rules; my $t = XML::Rules->new( qw/ stripspaces 8 /, rules => { 'dev0,devices,key0,key1,opt' => 'no content', 'param' => 'as array', }, ); my $XmlRef = $t->parse( $wanted ); dd $XmlRef; print $t->toXML( opt => $XmlRef->{opt}, undef, " ", ); __END__ { opt => { key0 => { devices => { dev0 => { param => [ { _content => "joe", id => "name" }, { _content => "user", id => "type" }, ], }, }, }, key1 => { devices => { dev0 => { param => [ { _content => "mary", id => "name" }, { _content => "user", id => "type" }, ], }, }, }, }, } <opt> <key0> <devices> <dev0> <param id="name">joe</param> <param id="type">user</param> </dev0> </devices> </key0> <key1> <devices> <dev0> <param id="name">mary</param> <param id="type">user</param> </dev0> </devices> </key1> </opt>
You still get to have a hairy hash, you still get your xml, and you don't spend days trying to make it "Simple"
In reply to Re^3: XMLout and keys/attributes
by Anonymous Monk
in thread XMLout and keys/attributes
by atreyu
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |