thunders has asked for the wisdom of the Perl Monks concerning the following question:

XML::Simple seems to be taking some liberties with the code I feed it. Lets say I have xml like this that I put in a data structure my $config = XMLin($configfile);
<config id="Installer"> <pclist> <pc>MYPC1</pc> <pc>MYPC2</pc> <pc>MYPC3</pc> </pclist> <installfrom>C:\install</installfrom> <installto> <path>C:\Program Files</path> <subdir>directory</subdir> </installto> <logon> <domain>mydomain</domain> <user>someuser</user> <pass>blahblah</pass> </logon> </config>
Then I manipulate the structure by adding a pc name with and changing $config->{'installto'}->{'subdir'} = "otherdirectory"; I feed the altered hashref to XMLout($config); and the output is a little different.
<pclist> <pc>MYPC1</pc> <pc>MYPC2</pc> <pc>MYPC3</pc> <pc>MYPC4</pc> </pclist> <logon pass="blahblah" domain="mydomain" user="someuser" /> <installto path="C:\Program Files" subdir="otherdirectory" /> </opt>
Somehow the pclist which refers to an array ref is fine. but the other nested tags get all fubared into single elements. Am I doing something wrong?

Replies are listed 'Best First'.
Re: XML formatting problems with XML::Simple
by mirod (Canon) on Jun 11, 2002 at 20:16 UTC

    May not Reading The Funny Manual? ;--) (with perldoc XML::Simple)

    Try using the noattr => 1 option with XMLout, it should solve your problem.

      You are correct. thanks.
      I also realized that to faithfully duplicate my code I needed to set the keeproot => 1 in both the XMLin and XMLout functions and that there doesn't seem to be a clean way to mix data contained in attributes and data in nested tags with this ::Simple tool.