// Create a custom builder to store the sub trees as a byte array instead of a full tree
ByteArrayCustomBuilder customBuilder = new ByteArrayCustomBuilder("utf-8");
// Register the custom builder on the builder so that they body payload is stored as bytes
builder.registerCustomBuilderForPayload(customBuilder);
// Create an output stream
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
writer = StAXUtils.createXMLStreamWriter(byteArrayOutputStream);