Vasilis,
Independently of the mechanics of writing the particular script you described, I'd like to ask about the circumstances in which you will use the script. In particular, are the XML documents going to be edited in FrameMaker? Is the inserted content always the same, or does it vary, for example for different users or the date and time?
I don't know your circumstances, but a different approach that you may want to consider is editing the documents in WYSIWYG view. You can provide users with a template that has the needed initial content. You can configure FrameMaker so that the browser resulting from the File > New command opens in the directory containing that template. The user can then complete the content using the WYSIWYG approach to editing structured documents that helps the user create valid documents that can then be saved as XML.
--Lynne