// Step 1: Load an XMLSignatureFactory instance. This factory class will
// be responsible for constructing almost all the major objects we need
// in working with XML Signature in JSR-105 APIs, except those related
// to KeyInfo.
XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM", new XMLDSigRI());
// Step 2: Decide on a digest method and create the reference object. We
// use the XMLSignatureFactory instance created in the first step to
// create both the DigestMethod and Reference objects.
Reference ref = fac.newReference("#invoice", fac.newDigestMethod(DigestMethod.SHA256, null));