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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.