}
public void run() throws SaxonApiException {
super.run();
Serializer serializer = makeSerializer();
XdmNode doc = source.read();
TreeWriter tree = new TreeWriter(runtime);
tree.startDocument(doc.getBaseURI());
for (XdmNode child : new AxisNodes(doc, Axis.CHILD)) {
if (child.getNodeKind() == XdmNodeKind.COMMENT) {
tree.addComment(child.getStringValue());
} else if (child.getNodeKind() == XdmNodeKind.PROCESSING_INSTRUCTION) {
tree.addPI(child.getNodeName().getLocalName(), child.getStringValue());
} else if (child.getNodeKind() == XdmNodeKind.TEXT) {
tree.addText(child.getStringValue());
} else {
tree.addStartElement(child);
tree.addAttributes(child);
tree.startContent();
// Serialize the *whole* thing, then strip off the start and end tags, because
// otherwise namespace fixup messes with the namespace bindings
ByteArrayOutputStream outstr = new ByteArrayOutputStream();
serializer.setOutputStream(outstr);
S9apiUtils.serialize(runtime, child, serializer);
String data = outstr.toString();
data = data.replaceAll("^<.*?>",""); // Strip off the start tag...
data = data.replaceAll("<[^<>]*?>$",""); // Strip off the end tag