Ignore:
Timestamp:
2015-01-09T15:30:46+13:00 (9 years ago)
Author:
Jeremy Symon
Message:

Fixed problems with XML parser introduced by the ordered hash change

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/package-kits/scripts/perllib/Greenstone/XML/Tidy.pm

    r29679 r29680  
    7575        my $attr = shift;
    7676        if (scalar keys %$attr > 0) {
    77             $hash->set ('.attr' => Hash::Ordered->new ($attr));
     77            my $attr_ordered = Hash::Ordered->new;
     78            for my $key (keys %$attr) {
     79                $attr_ordered->set ($key => $attr->{$key});
     80            }
     81            $hash->set ('.attr' => $attr_ordered);
    7882        }
    7983        # Read any child elements or text value
     
    121125        select $FH;
    122126    }
     127    sub escape {
     128        my @r;
     129        for (@_) {
     130            my $str = ''. $_;
     131            $str =~ s/(['\\])/\\$1'/g;
     132            push @r, $str;
     133        }
     134        return @r;
     135    }
    123136    sub open_tag {
    124137        my ($indent, $tag, $attr) = @_;
    125138        print $indent, "<", $tag;
    126139        if (defined $attr) {
    127             for my $key ($attr->keys) {
    128                 print " ", $key, '="', $attr->get ($key), '"';
     140            my $iter = $attr->iterator;
     141            while (my ($key, $value) = $iter->()) {
     142                print " ", $key, '="', escape $value, '"';
    129143            }
    130144        }
     
    160174                    # If the element only has a value with attributes,
    161175                    # it can be formatted on one line
    162                     if (scalar keys %$val == 2 and $val->exists ('.value')) {
     176                    if (scalar $val->keys == 2 and $val->exists ('.value')) {
    163177                        print $val->get ('.value'), "</", $key, ">\n";
    164178                    } else {
Note: See TracChangeset for help on using the changeset viewer.