NodeValue nv = (NodeValue) args[0].itemAt(0);
if (nv.getImplementationType() == NodeValue.IN_MEMORY_NODE) {
NodeImpl node = (NodeImpl) nv;
reader = new InMemoryXMLStreamReader(node.getDocument(), node.getDocument());
} else {
NodeProxy proxy = (NodeProxy) nv;
reader = context.getBroker().newXMLStreamReader(new NodeProxy(proxy.getDocument(), NodeId.DOCUMENT_NODE, proxy.getDocument().getFirstChildAddress()), false);
}
nv = (NodeValue) args[1].itemAt(0);
if (nv.getImplementationType() == NodeValue.IN_MEMORY_NODE)
throw new XPathException("patch cannot be applied to in-memory documents");
NodeProxy diffProxy = (NodeProxy) nv;
DocumentImpl diff = diffProxy.getDocument();
MemTreeBuilder builder = context.getDocumentBuilder();
DocumentBuilderReceiver receiver = new DocumentBuilderReceiver(builder);
Patch patch = new Patch(context.getBroker(), diff);
if (isCalledAs("annotate"))