I am not expert enough in XML to know for 100% sure, but I don't think my file is "mixed" and still XML::Simple throws away attributes when I write out the object. I've stripped it down as much as possible here for example purposes:



use XML::Simple;
use Data:umper;

my ( $ref_XML_file, $out_XML_file, $dump_file ) = ARGV;

my $XML_declaration = "<?xml version='1.0' encoding='UTF-8'?>";

open( OUT_XML_FILE, ">$out_XML_file" ) or die "Cannot open $out_XML_file for writing: $!";
open( DUMP_FILE, ">$dump_file" ) or die "Cannot open $out_XML_file for writing: $!";

my $xml = new XML::Simple;
my $xml_ref_hashref = $xml->XMLin($ref_XML_file, KeepRoot => 1 );

print DUMP_FILE Dumper( $xml_ref_hashref ), "\n";
print OUT_XML_FILE $xml->XMLout( $xml_ref_hashref, XmlDecl => $XML_declaration, KeepRoot => 1, NoAttr => 1 );
<?xml version='1.0' encoding='UTF-8'?>
<rootTag name='NameGoesHere' version='1.0'>
<ListOfThings thingID='40DD9' otherID='8026' isAThing='true' thingName='xyz123'>
<thingStuff >
<moreThingStuff isStuff='true' name='THX1138' duration='86400' />

If I run ./stripped_test.pl ./test_case.xml ./out.xml ./dump.txt

I get:


<?xml version='1.0' encoding='UTF-8'?>

NOTE THAT "moreThingStuff" has completely disappeared.

Here is the dump file:

$VAR1 = {
'rootTag' => {
'ListOfThings' => {
'otherID' => '8026',
'thingID' => '40DD9',
'thingName' => 'xyz123',
'thingStuff' => {
'moreThingStuff' => {
'isStuff' => 'true',
'name' => 'THX1138',
'duration' => '86400'
'isAThing' => 'true'
'version' => '1.0',
'name' => 'NameGoesHere'

Is there a simple way to preserve this element on write-out? Or have I run into a bug? Or is this just not "simple" enough a structure for XML::Simple and I have to use something else? (If the latter, suggestions gratefully accepted.)