String fileRef = prefix + "in/37_c14n.xml";
//String c14nURI = Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS;
//boolean validating = true;
DocumentBuilder db = XMLUtils.createDocumentBuilder(false, false);
org.xml.sax.EntityResolver resolver = new TestVectorResolver();
db.setEntityResolver(resolver);
Document doc = db.parse(resolver.resolveEntity(null, fileIn));
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()) "
+ "]";
Map<String, String> namespace = new HashMap<String, String>();
namespace.put("ietf", "http://www.ietf.org");
XPathFactory xpf = XPathFactory.newInstance();
XPath xPath = xpf.newXPath();
DSNamespaceContext namespaceContext =
new DSNamespaceContext(namespace);
xPath.setNamespaceContext(namespaceContext);
NodeList nodes = (NodeList)xPath.evaluate(xpath, doc, XPathConstants.NODESET);
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);
assertEquals(new String(refBytes),new String(c14nBytes));
}