root.setServiceArray(new AbstractServiceType[]{realm});
//Above code inserts gbean using xsi:type=dep:GBeanType. We also need to account for the substitution group
//by changing the qname:
XmlCursor gbeanCursor = root.newCursor();
try {
if (!gbeanCursor.toChild(ServiceDocument.type.getDocumentElementName())) {
throw new RuntimeException("Could not find service element");
}
gbeanCursor.setName(GBEAN_QNAME);