child.addAttribute(new Attribute("xml:lang", Namespace.XML_NAMESPACE, "en"));
middle.appendChild(child);
String expected = "<tuck xml:lang=\"fr\"><child xml:lang=\"en\"></child></tuck>";
ByteArrayOutputStream out = new ByteArrayOutputStream();
Canonicalizer canonicalizer = new Canonicalizer(out,
Canonicalizer.EXCLUSIVE_XML_CANONICALIZATION_WITH_COMMENTS);
Document doc = new Document(pdu);
Nodes subset = doc.query("/* | //child | //@*");
canonicalizer.write(subset);
byte[] result = out.toByteArray();
out.close();
String s = new String(out.toByteArray(), "UTF8");
assertEquals(expected, s);