-my $nchanges = modify_xml_document($xc, \%fieldsByKey, \%data);
-#ZOOM::IRSpy::_really_rewrite_record($conn, $xc->getContextNode());
-print "The record has been updated (nchanges=$nchanges).\n";
-print $xc->getContextNode()->toString();
+
+my $oldText = $xc->getContextNode()->toString();
+my @changedFields = modify_xml_document($xc, \%fieldsByKey, \%data);
+my $nchanges = @changedFields;
+my $newText = $xc->getContextNode()->toString();
+print("Document modified with $nchanges change", $nchanges == 1 ? "" : "s",
+ ": ", join(", ", map { $_->[2] } @changedFields), "\n");
+
+if ($opts{w}) {
+ ZOOM::IRSpy::_rewrite_zeerex_record($conn, $xc->getContextNode(), $id);
+ 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);
+}