//iterate through the output vars and add them to the merged doc.
for (int i = 0; i < children.size(); i++) {
Object o = children.get(i);
if (o instanceof Element) {
Element child = (Element) o;
child.detach();
//the input data will be removed from the merged doc and
//the output data will be added.
//System.out.println(child.getName());
mergedDoc.getRootElement().removeChild(child.getName());
mergedDoc.getRootElement().addContent(child);