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

You need to force a reference, otherwise XML::Simple folds simple elements into attributes

by inq123 (Sexton)
on Mar 21, 2005 at 23:40 UTC ( #441341=note: print w/replies, xml ) Need Help??


in reply to XML::Simple "transforming data"

The solution is actually just posted above - use ForceArray => 1 when you do XMLin(); The mechanism is as my title suggested: as long as you force a reference out of the value, that value will be treated as element instead of attribute when XMLout writes it out.

Here's the set of options that I found the best (for my usage, and probably for general usage) for XML::Simple:

my $obj = XMLin($filename, ForceArray => 1, ForceContent => 1, KeepRoo +t => 1, ContentKey => '_c', KeyAttr => []); open(OUT, ">$filename-1"); print OUT XMLout($obj, KeepRoot => 1, ContentKey => '_c', KeyAttr => [ +]);
Hope it helps.
  • Comment on You need to force a reference, otherwise XML::Simple folds simple elements into attributes
  • Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2020-02-23 14:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (102 votes). Check out past polls.

    Notices?