ResultSequence rs = session.submitRequest (request);
while (rs.hasNext()) {
ResultItem rsItem = rs.next();
XdmItem item = rsItem.getItem();
// FIXME: This needs work...
if (item instanceof XdmDocument || item instanceof XdmElement) {
XdmNode xccXML = parseString(item.asString());
result.write(xccXML);
} else if (item instanceof XdmBinary) {
String base64 = Base64.encodeBytes(((XdmBinary) item).asBinaryData());
TreeWriter treeWriter = new TreeWriter(runtime);
treeWriter.startDocument(step.getNode().getBaseURI());
treeWriter.addStartElement(wrapper);
if (XProcConstants.NS_XPROC_STEP.equals(wrapper.getNamespaceURI())) {
treeWriter.addAttribute(_encoding, "base64");
} else {
treeWriter.addAttribute(c_encoding, "base64");
}
treeWriter.startContent();
treeWriter.addText(base64);
treeWriter.addEndElement();
treeWriter.endDocument();
XdmNode node = treeWriter.getResult();
result.write(node);
} else {
String text = item.asString();
TreeWriter treeWriter = new TreeWriter(runtime);
treeWriter.startDocument(step.getNode().getBaseURI());
treeWriter.addStartElement(wrapper);
treeWriter.startContent();
treeWriter.addText(text);