It seems like you could do this a lot more simply with XML::Simple. If the default output is not good enough for your purposes (and it probably isn't), then you can tweak the output with the options.
Comment on Re: XML serialization with attributes handling