Package: libxml-mini-perl
Version: 1.2.8-2

According to the XML 1.1 W3C Recommendation
(http://www.w3.org/TR/2004/REC-xml11-20040204/) section 2.8 the XML header is
declared as
XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S?'?>'
which means that the version attribute is supposed to be left from the
encoding. Unfortunately the header class of XML::Mini always sorts its
attributes alphabetically before printing, which makes it impossible to create
a header that is accepted by a different program using libxml.

I have included an example program, as well as a patch fixing the problem
mentioned above.

Regards
  Marc Laue
#! /usr/bin/perl

use strict;
use XML::Mini::Document;

my $doc=XML::Mini::Document->new();
my $root=$doc->getRoot();
my $header=$root->prependChild(XML::Mini::Element::Header->new('xml'));
$header->attribute('version','1.0');
$header->attribute('encoding','UTF-8');
print $doc->toString(),"\n";
diff -ur libxml-mini-perl-1.2.8.orig/lib/XML/Mini/Element/Header.pm 
libxml-mini-perl-1.2.8/lib/XML/Mini/Element/Header.pm
--- libxml-mini-perl-1.2.8.orig/lib/XML/Mini/Element/Header.pm  2003-01-26 
08:44:01.000000000 +0000
+++ libxml-mini-perl-1.2.8/lib/XML/Mini/Element/Header.pm       2005-10-26 
08:18:35.000000000 +0000
@@ -40,9 +40,32 @@
     my $retString = "$spaces<?". $self->name() . ' ';
     
     my $attribString;
+
+    # ensure the order of attributes inside the header conforms to W3C
+    # Recommendation for XML 1.1
+    my $atValue;
+    $atValue = $self->{'_attributes'}->{'version'};
+    if (defined $atValue)
+    {
+       $attribString .= qq|version="$atValue" |;
+    }
+    $atValue = $self->{'_attributes'}->{'encoding'};
+    if (defined $atValue)
+    {
+       $attribString .= qq|encoding="$atValue" |;
+    }
+    $atValue = $self->{'_attributes'}->{'standalone'};
+    if (defined $atValue)
+    {
+       $attribString .= qq|standalone="$atValue" |;
+    }
+
     foreach my $atName (sort keys %{$self->{'_attributes'}})
     {
-       $attribString .= qq|$atName="$self->{'_attributes'}->{$atName}" |;
+       if (($atName ne 'version') && ($atName ne 'encoding') && ($atName ne 
'standalone'))
+       {
+           $attribString .= qq|$atName="$self->{'_attributes'}->{$atName}" |;
+       }
     }
     
     if (defined $attribString && $attribString =~ m|\S|)
@@ -64,10 +87,34 @@
     
     my $retString = '<? ' . $self->name();
     my $attribString;
+
+    # ensure the order of attributes inside the header conforms to W3C
+    # Recommendation for XML 1.1
+    my $atValue;
+    $atValue = $self->{'_attributes'}->{'version'};
+    if (defined $atValue)
+    {
+       $attribString .= qq|version="$atValue" |;
+    }
+    $atValue = $self->{'_attributes'}->{'encoding'};
+    if (defined $atValue)
+    {
+       $attribString .= qq|encoding="$atValue" |;
+    }
+    $atValue = $self->{'_attributes'}->{'standalone'};
+    if (defined $atValue)
+    {
+       $attribString .= qq|standalone="$atValue" |;
+    }
+
     foreach my $atName (sort keys %{$self->{'_attributes'}})
     {
-       $attribString .= qq|$atName="$self->{'_attributes'}->{$atName}" |;
-    } 
+       if (($atName ne 'version') && ($atName ne 'encoding') && ($atName ne 
'standalone'))
+       {
+           $attribString .= qq|$atName="$self->{'_attributes'}->{$atName}" |;
+       }
+    }
+
     if (defined $attribString && $attribString =~ m|\S|)
     {
        $retString .= $attribString;

Reply via email to