added check for broken CDATA at beginning, fix also broken delimiters
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 6 Jun 2006 12:34:25 +0000 (12:34 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 6 Jun 2006 12:34:25 +0000 (12:34 +0000)
git-svn-id: file:///home/dpavlin/private/svn/webpac/trunk@747 13eb9ef6-21d5-0310-b721-a9d68796d827

all2xml.pl

index 0d0f1ba..128b1ec 100755 (executable)
@@ -76,6 +76,9 @@ my $use_lhash_cache = 1;
 
 my $last_field_name;   # cache to prevent repeated fields
 
+my $broken_cdata = XMLin('<foo><![CDATA[<bar>]]></foo>') eq '<bar>>';
+warn "XML::Simple on this system seems broken with <![CDATA[..]]>.\n" if ($broken_cdata);
+
 sub data2xml {
 
        use xmlify;
@@ -207,6 +210,7 @@ sub data2xml {
                        delete $x->{value};
                        delete $x->{delimiter};
                        $x->{content} = $v;
+                       $d =~ s#>$## if ($d && $broken_cdata);
                        $x->{delimiter} = $d;
                }
                return $x;
@@ -488,7 +492,7 @@ sub data2xml {
                        if ($val) {
                                $display_data .= $delimiter.$val if ($d);
                                $swish_data .= " ".$val if ($s);
-                               $index->insert($field, $val, $path) if ($i);
+                               $index->insert($field, $val, $val, $path) if ($i);
                        }
 
                        if ($iterate_by_page) {
@@ -705,6 +709,13 @@ foreach my $database ($cfg->Sections) {
        my $tag = $cfg->val($database, 'import_xml_tag') || $type2tag{$type_base} || die "can't find which tag to use for type $type";
        $config=XMLin($import_xml_file, ForceArray => [ $tag, 'config', 'format' ], ForceContent => 1 );
 
+       # check for broken XML::Simple
+       if ( $broken_cdata ) {
+               map {
+                       $config->{format}->{$_}->{content} =~ s#>$##;
+               } keys %{ $config->{format} };
+       }
+
        # helper for progress bar
        sub fmt_time {
                my $t = shift || 0;