DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
dfactory.setNamespaceAware(true);
DocumentBuilder db = dfactory.newDocumentBuilder();
org.xml.sax.EntityResolver resolver = new TestVectorResolver();
db.setEntityResolver(resolver);
Document doc = db.parse(resolver.resolveEntity(null, fileIn));
//J-
Element nscontext = XMLUtils.createDSctx(doc, "ietf", "http://www.ietf.org");
String xpath = "(//. | //@* | //namespace::*)"
+ "[ "
+ "self::ietf:e1 or "
+ "(parent::ietf:e1 and not(self::text() or self::e2)) or "
+ "count(id(\"E3\")|ancestor-or-self::node()) = count(ancestor-or-self::node()) "
+ "]";
//J+
CachedXPathAPI xpathAPI = new CachedXPathAPI();
XMLUtils.circumventBug2650(doc);
NodeList nodes = xpathAPI.selectNodeList(doc, xpath, nscontext);
Canonicalizer c14n =
Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
byte c14nBytes[] = c14n.canonicalizeXPathNodeSet(nodes);
InputStream refStream = resolver.resolveEntity(null,
fileRef).getByteStream();
byte refBytes[] = JavaUtils.getBytesFromStream(refStream);
boolean equal = java.security.MessageDigest.isEqual(refBytes, c14nBytes);
assertTrue(equal);