Changeset 29680
- Timestamp:
- 2015-01-09T15:30:46+13:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/package-kits/scripts/perllib/Greenstone/XML/Tidy.pm
r29679 r29680 75 75 my $attr = shift; 76 76 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); 78 82 } 79 83 # Read any child elements or text value … … 121 125 select $FH; 122 126 } 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 } 123 136 sub open_tag { 124 137 my ($indent, $tag, $attr) = @_; 125 138 print $indent, "<", $tag; 126 139 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, '"'; 129 143 } 130 144 } … … 160 174 # If the element only has a value with attributes, 161 175 # 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')) { 163 177 print $val->get ('.value'), "</", $key, ">\n"; 164 178 } else {
Note:
See TracChangeset
for help on using the changeset viewer.