NodeList nl =
doc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
if (nl.getLength() == 0) {
throw new Exception("Cannot find Signature element");
}
DOMStructure domSignature = new DOMStructure(nl.item(0));
// unmarshal the XMLSignature
XMLSignature signature = fac.unmarshalXMLSignature(domSignature);
// create copy of Signature
XMLSignature newSignature = fac.newXMLSignature
(signature.getSignedInfo(), null, signature.getObjects(),
signature.getId(), signature.getSignatureValue().getId());
// Sign the template
Node parent = domSignature.getNode().getParentNode();
DOMSignContext signContext = new DOMSignContext(SIGN_KEYS[0], parent);
// remove the signature node (since it will get recreated)
parent.removeChild(domSignature.getNode());
newSignature.sign(signContext);
TestUtils.validateSecurityOrEncryptionElement(parent.getLastChild());
// check that Object element retained namespace definitions
Element objElem = (Element)parent.getFirstChild().getLastChild();