elem1.appendChild("content");
pdu.appendChild(elem1);
String expected = "<n1:elem1 xmlns:n1=\"http://b.example\">content</n1:elem1>";
ByteArrayOutputStream out = new ByteArrayOutputStream();
Canonicalizer canonicalizer = new Canonicalizer(out,
Canonicalizer.EXCLUSIVE_XML_CANONICALIZATION_WITH_COMMENTS);
XPathContext context = new XPathContext("n1", "http://b.example");
Document doc = new Document(pdu);
canonicalizer.write(doc.query("(//. | //@* | //namespace::*)[ancestor-or-self::n1:elem1]", context));
byte[] result = out.toByteArray();
out.close();
String s = new String(out.toByteArray(), "UTF8");
assertEquals(expected, s);