/[webpac]/trunk/all2xml.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/all2xml.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 274 by dpavlin, Sun Mar 14 11:50:29 2004 UTC revision 298 by dpavlin, Fri Apr 2 23:31:25 2004 UTC
# Line 17  $|=1; Line 17  $|=1;
17    
18  my $config_file = $0;  my $config_file = $0;
19  $config_file =~ s/\.pl$/.conf/;  $config_file =~ s/\.pl$/.conf/;
20    $config_file = $ARGV[0] if (-f $ARGV[0]);
21  die "FATAL: can't find configuration file '$config_file'" if (! -e $config_file);  die "FATAL: can't find configuration file '$config_file'" if (! -e $config_file);
22    
23  my $config;  my $config;
# Line 150  sub data2xml { Line 151  sub data2xml {
151                  }                  }
152          }          }
153    
154    
155            # init variables for different types
156          sub init_visible_type($) {          sub init_visible_type($) {
157                  my $type = shift;                  my $type = shift;
158    
# Line 170  sub data2xml { Line 173  sub data2xml {
173                  return ($s,$se,$d,$i,$il);                  return ($s,$se,$d,$i,$il);
174          }          }
175    
176    
177            # convert
178            #
179            # <tag>
180            #  <delimiter>, </delimiter>
181            #  <value>200a</value>
182            # </tag>
183            #
184            # to
185            #
186            # <tag delimiter=", ">200a</tag>
187            #
188            # but without loosing spaces in delimiter (becasue
189            # new XML::Simple strips spaces in attribute values
190            # as defined in XML specification)
191            #
192            sub unroll_x($) {
193                    my $x = shift;
194    
195                    if (defined $x->{value}) {
196                            my ($v,$d) = ($x->{value}->{content}, $x->{delimiter}->{content});
197                            delete $x->{value};
198                            delete $x->{delimiter};
199                            $x->{content} = $v;
200                            $x->{delimiter} = $d;
201                    }
202                    return $x;
203            }
204    
205          # begin real work: go field by field          # begin real work: go field by field
206          foreach my $field (@sorted_tags) {          foreach my $field (@sorted_tags) {
207    
# Line 203  sub data2xml { Line 235  sub data2xml {
235    
236                  foreach my $x (@{$config->{indexer}->{$field}->{$tag}}) {                  foreach my $x (@{$config->{indexer}->{$field}->{$tag}}) {
237    
238                            $x = unroll_x($x);
239    
240                          my $format = x($x->{content});                          my $format = x($x->{content});
241                          my $delimiter = x($x->{delimiter}) || ' ';                          my $delimiter = x($x->{delimiter}) || ' ';
242    
# Line 212  sub data2xml { Line 246  sub data2xml {
246    
247                          # what will separate last line from this one?                          # what will separate last line from this one?
248                          if ($display_data && $x->{append}) {                          if ($display_data && $x->{append}) {
249                                  $line_delimiter = ' ';                                  $line_delimiter = $delimiter;
250                          } elsif ($display_data) {                          } elsif ($display_data) {
251                                  $line_delimiter = '<br/>';                                  $line_delimiter = '<br/>';
252                          }                          }
# Line 429  sub data2xml { Line 463  sub data2xml {
463                  # now try to parse variables from configuration file                  # now try to parse variables from configuration file
464                  foreach my $x (@{$config->{indexer}->{$field}->{'config'}}) {                  foreach my $x (@{$config->{indexer}->{$field}->{'config'}}) {
465    
466                            $x = unroll_x($x);
467    
468                          my $delimiter = x($x->{delimiter}) || ' ';                          my $delimiter = x($x->{delimiter}) || ' ';
469                          my $val = $cfg->val($database, x($x->{content}));                          my $val = $cfg->val($database, x($x->{content}));
470    
# Line 613  print STDERR "reading ./import_xml/$type Line 649  print STDERR "reading ./import_xml/$type
649          my $type_base = $type;          my $type_base = $type;
650          $type_base =~ s/_.+$//g;          $type_base =~ s/_.+$//g;
651    
652          $config=XMLin("./import_xml/$type.xml", forcearray => [ $type2tag{$type_base}, 'config', 'format' ], forcecontent => 1);          $config=XMLin("./import_xml/$type.xml", ForceArray => [ $type2tag{$type_base}, 'config', 'format' ], ForceContent => 1 );
653    
654          # output current progress indicator          # output current progress indicator
655          my $last_p = 0;          my $last_p = 0;
# Line 883  __END__ Line 919  __END__
919    
920  all2xml.pl - read various file formats and dump XML for SWISH-E  all2xml.pl - read various file formats and dump XML for SWISH-E
921    
922    =head1 SYNOPSYS
923    
924     $ all2xml.pl [test.conf]
925    
926  =head1 DESCRIPTION  =head1 DESCRIPTION
927    
928  This command will read ISIS data file using OpenIsis perl module, MARC  This command will read ISIS data file using OpenIsis perl module, MARC
# Line 891  create one XML file for usage with I<SWI Line 931  create one XML file for usage with I<SWI
931  this script B<isn't general xml generator> from isis files (isis allready  this script B<isn't general xml generator> from isis files (isis allready
932  has something like that). Output of this script is tailor-made for SWISH-E.  has something like that). Output of this script is tailor-made for SWISH-E.
933    
934    If no configuration file is specified, it will use default one called
935    C<all2xml.conf>.
936    
937  =head1 BUGS  =head1 BUGS
938    
939  Documentation is really lacking. However, in true Open Source spirit, source  Documentation is really lacking. However, in true Open Source spirit, source

Legend:
Removed from v.274  
changed lines
  Added in v.298

  ViewVC Help
Powered by ViewVC 1.1.26