I guess you can.
However, maybe you should have a look on the XSLT technology. It allows you to recombine XML files.
The language is a bit disturbing at first but you can get nice results.
I know this is not scripting but XSLT is a know technology for recombining xml, that's why I offer you to have a look on it.
I think that if your final intention is to place the XML into Indesign, you can specify the XSLT file to use for the import.
Thanks for your suggesion.