3 # $Id: test-xml-update.pl,v 1.2 2006-11-01 10:31:57 mike Exp $
6 # perl -I ../lib ./test-xml-update.pl bagel.indexdata.dk:210/gils
11 use ZOOM::IRSpy::Utils qw(irspy_xpath_context modify_xml_document);
13 # This array copied from ../web/htdocs/details/edit.mc
16 [ protocol => 0, "Protocol", "e:serverInfo/\@protocol" ],
17 [ host => 0, "Host", "e:serverInfo/e:host" ],
18 [ port => 0, "Port", "e:serverInfo/e:port" ],
19 [ dbname => 0, "Database Name", "e:serverInfo/e:database",
21 [ username => 0, "Username (if needed)", "e:serverInfo/e:authentication/e:user",
23 [ password => 0, "Password (if needed)", "e:serverInfo/e:authentication/e:password",
25 [ title => 0, "title", "e:databaseInfo/e:title",
27 [ description => 5, "Description", "e:databaseInfo/e:description",
29 [ author => 0, "Author", "e:databaseInfo/e:author",
30 qw(e:title e:description) ],
31 [ contact => 0, "Contact", "e:databaseInfo/e:contact",
32 qw(e:title e:description) ],
33 [ extent => 3, "Extent", "e:databaseInfo/e:extent",
34 qw(e:title e:description) ],
35 [ history => 5, "History", "e:databaseInfo/e:history",
36 qw(e:title e:description) ],
37 [ language => 0, "Language of Records", "e:databaseInfo/e:langUsage",
38 qw(e:title e:description) ],
39 [ restrictions => 2, "Restrictions", "e:databaseInfo/e:restrictions",
40 qw(e:title e:description) ],
41 [ subjects => 2, "Subjects", "e:databaseInfo/e:subjects",
42 qw(e:title e:description) ],
45 if (@ARGV < 1 || @ARGV % 2 == 0) {
46 print STDERR "Usage: %0 <id> [<key1> <value1> ...]\n";
49 my($id, %data) = @ARGV;
51 my $conn = new ZOOM::Connection("localhost:3313/IR-Explain---1", 0,
52 user => "admin", password => "fruitbat");
53 $conn->option(elementSetName => "zeerex");
56 my $query = qq[rec.id="$qid"];
57 my $rs = $conn->search(new ZOOM::Query::CQL($query));
60 print STDERR "$0: no record with ID '$id'";
64 my $rec = $rs->record(0);
65 my $xc = irspy_xpath_context($rec);
66 my %fieldsByKey = map { ( $_->[0], $_) } @fields;
67 my $oldText = $xc->getContextNode()->toString();
68 my $nchanges = modify_xml_document($xc, \%fieldsByKey, \%data);
69 my $newText = $xc->getContextNode()->toString();
70 #ZOOM::IRSpy::_really_rewrite_record($conn, $xc->getContextNode());
71 print "The record has been updated (nchanges=$nchanges).\n";
73 # Now display diffs between the original and modified records
74 my $oldFile = "/tmp/old.txu.$$";
75 my $newFile = "/tmp/new.txu.$$";
76 open OLD, ">$oldFile";
79 open NEW, ">/tmp/new.txu.$$";
82 system("diff $oldFile $newFile");