--- trunk/all2xml.pl 2003/07/04 17:57:11 59 +++ trunk/all2xml.pl 2003/07/04 20:11:48 62 @@ -56,7 +56,8 @@ # format in XML file my %type2tag = ( 'isis' => 'isis', - 'excel' => 'column' + 'excel' => 'column', + 'marc' => 'marc', ); sub data2xml { @@ -176,6 +177,7 @@ # now try to parse variables from configuration file foreach my $x (@{$config->{indexer}->{$field}->{'config'}}) { + my $delimiter = x($x->{delimiter}) || ' '; my $val = $cfg->val($database, x($x->{content})); my ($s,$d,$i) = (1,1,0); # swish, display default @@ -184,7 +186,7 @@ ($s,$d,$i) = (0,0,1) if (lc($x->{type}) eq "index"); if ($val) { - $display_data .= $val if ($d); + $display_data .= $delimiter.$val if ($d); $swish_data .= $val if ($s); $index->insert($field, $val, $path) if ($i); } @@ -366,6 +368,48 @@ $xml = $cp2utf->convert($xml); use bytes; # as opposed to chars print "Path-Name: $swishpath\n"; + print "Content-Length: ".(length($xml)+1)."\n"; + print "Document-Type: XML\n\n$xml\n"; + } + } + } elsif ($type_base eq "marc") { + ## XXX + use MARC; + + $import2cp = Text::Iconv->new($config->{marc_codepage},$codepage); + my $marc_file = $cfg -> val($database, 'marc_file') || die "$database doesn't have 'marc_file' defined!"; + + # optional argument is format + my $format = x($config->{format}) || 'usmarc'; + + my %id_stored; # to aviod duplicates + + print STDERR "Reading MARC file '$marc_file'\n"; + + my $marc = new MARC; + my $nr = $marc->openmarc({ + file=>$marc_file, format=>$format + }) || die "Can't open MARC file '$marc_file'"; + + my $i=0; # record nr. + my $inc=1; + my $max_i=1000; + + my $rec; + + while ($marc->nextmarc(1)) { + + # XXX + progress($i, $max_i); + $i += $inc; + $inc = -$inc if ($i > $max_i || $i < 0); + + my $swishpath = $database."#".$i; + + if (my $xml = data2xml($type_base,$marc,$add_xml,$cfg,$database)) { + $xml = $cp2utf->convert($xml); + use bytes; # as opposed to chars + print "Path-Name: $swishpath\n"; print "Content-Length: ".(length($xml)+1)."\n"; print "Document-Type: XML\n\n$xml\n"; }