xquery in java api, multiple insert

hi,
I’m inserting multiple elements into a certain node.
I’m using xquery and right now, I’m using this code:

for (int i=0; i< elementIds.length; ++i) {
     xpathQuery2 = "update insert <element_id>"+elementIds[i]+"</element_id> into "+xpathQuery1;
     xQuery = TXQuery.newInstance( xpathQuery2);
     resp2 = xmlAccessor.xquery( xQuery); // techn. update
}

I was wondering if there is a better solution to this, possibly a better xquery statement - it doesn’t seem very efficient to me to call the xquery method over and over!
I couldn’t find anything on this in the docs, so comments welcome!
thanks!

Hi,
you can do it all in one XQuery statement. The trick is to insert a sequence of nodes rather than a single node:


xpathQuery2 = "update insert ("
for (int i=0; i< elementIds.length; ++i) { 
     xpathQuery2 =xpathQuery2 + "<element_id>"+elementIds[i]+"</element_id>"
}
     xpathQuery2 = xpathQuery2 + ") into "+xpathQuery1; 
     xQuery = TXQuery.newInstance( xpathQuery2); 
     resp2 = xmlAccessor.xquery( xQuery); // techn. update 

superb! that’s exactly what I need!

seperate the sequence’s elements with “,” and it works!

thanks a lot!