It's hard to tell without your source XML but it could be here:
var dataNode = xmlDoc.createElement("data")
Does this already exist in your source file?
If so, you need to get this to point to the existing 'data' node, not create a new one. Perhaps:
var dataNode = xmlDoc.getElementsByTagName("data").Item(1)
|