Hi Andrei and welcome to our forum!
A similiar action is accomplished in this tutorial:
http://infopathdev.com/howto/tutorials/default.aspx?i=80c11a66b08a4572bc2b17f391319a0f(Just skip down to the code and look at the appendChild() function)
Here's an excerpt:
var oRows = XDocument.DOM.selectNodes("/my:myFields/my:Document/my:Page/my:Table/my:Row");
// Save a sample node from this list for later - we will have to clone
// it to add our rows back in.
var oSampleRow = oRows.nextNode();
//..........
// Create a new row by cloning our sample row.
// This node must be cloned using "deep" mode to maintain structure of the
// DOM below it. However, we are about to overwrite all of the nodes anyway.
var oNewRow = oSampleRow.cloneNode(true);
// Set the values in the new row from the source row
// that we are reading from on this iteration.
oNewRow.selectSingleNode("my:Year").text = oSrc.selectSingleNode("@year").nodeValue;
oNewRow.selectSingleNode("my:Make").text = oSrc.selectSingleNode("@make").nodeValue;
oNewRow.selectSingleNode("my:Model").text = oSrc.selectSingleNode("@model").nodeValue;
oNewRow.selectSingleNode("my:Description").text = oSrc.selectSingleNode("@description").nodeValue;
// Add the row to the table that is on the current page.
XDocument.DOM.selectSingleNode("/my:myFields/my:Document/my:Page[" + iCurrentPageIndex + "]/my:Table").appendChild(oNewRow);All that to say, try looking at appendChild() instead of xCollection functions. I've never worked with xCollection, but I know that appendChild() has never failed me!
I hope this information helps you out, please let us know how it goes!
---------------
Matt Faus
InfoPath Dev Texas
Matt Faus / Microsoft InfoPath MVPQdabra® Software / Streamline data gathering to turn process into knowledge