http://www.perlmonks.org?node_id=1004821


in reply to Adding Elements to XML

SO FAR

Well, naturally, appendChild adds one to the end, perhaps you want  $root->insertBefore( $newNode, $root->firstChild );

RESULTS I WANT

You may not have a choice, but if you do, you should think about WANTing a different xml structure :) for example, one that isn't so recursive -- one where the definitions are children (not siblings) of keys -- its a dictionary :)