-#ZOOM::IRSpy::_really_rewrite_record($conn, $xc->getContextNode());
-print "The record has been updated (nchanges=$nchanges).\n";
-print $xc->getContextNode()->toString();
+my $newText = $xc->getContextNode()->toString();
+print "Document modified with $nchanges change", $nchanges==1?"":"s", "\n";
+
+if ($opts{w}) {
+ ZOOM::IRSpy::_really_rewrite_record($conn, $xc->getContextNode());
+ print "Rewrote record '$id'\n";
+}
+
+if ($opts{n}) {
+ foreach my $key (sort keys %data) {
+ my $ref = $fieldsByKey{$key};
+ my($name, $nlines, $caption, $xpath, @addAfter) = @$ref;
+ print "New $caption ($xpath) = '", $xc->findvalue($xpath), "'\n";
+ }
+}
+
+if ($opts{x}) {
+ print $newText;
+}
+
+if ($opts{d}) {
+ my $oldFile = "/tmp/old.txu.$$";
+ my $newFile = "/tmp/new.txu.$$";
+ open OLD, ">$oldFile";
+ print OLD $oldText;
+ close OLD;
+ open NEW, ">/tmp/new.txu.$$";
+ print NEW $newText;
+ close NEW;
+ system("diff $oldFile $newFile");
+ unlink($oldFile);
+ unlink($newFile);
+}