The XML file I need to create is like
<file>
<state>$state</state>
<timestamp>$time</timestamp>
<location>$location</location>
....
</file>
I don't want to use several print to create the needed XML file, what I'm expecting is to have a template, which defines both the structure and format of the XML.
Then when create the XML file, I just need to provide the actually values for the variables in the template and write the specified template to a newly created file once, only once.