Element newReferenceElement = (Element) xPathExpression.evaluate(clonedEncryptedElement, XPathConstants.NODE);
newReferenceElement.removeAttribute("URI");
newReferenceElement.setAttributeNS(null, "URI", "#G2");
Element securityHeaderNode = (Element) encryptedKeyElement.getParentNode();
securityHeaderNode.insertBefore(clonedEncryptedElement, encryptedKeyElement);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
javax.xml.transform.Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
transformer.transform(new DOMSource(securedDocument), new StreamResult(baos));