From: Grant M. <gr...@us...> - 2002-02-05 22:24:01
|
Update of /cvsroot/perl-xml/xml-simple In directory usw-pr-cvs1:/tmp/cvs-serv6199 Modified Files: Simple.pm Log Message: added warning re parseropts being deprecated - added missing support for default namespaces on output - added code to workaround outstanding issues in NamespaceSupport::declare_prefix() - removed redundant code to translate Clarkian names other than when they are hash keys - added CVS Id Index: Simple.pm =================================================================== RCS file: /cvsroot/perl-xml/xml-simple/Simple.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Simple.pm 2002/01/19 22:30:05 1.2 +++ Simple.pm 2002/02/05 22:23:58 1.3 @@ -68,6 +68,7 @@ my $DefXmlDecl = qq(<?xml version='1.0' standalone='yes'?>); my $xmlns_ns = 'http://www.w3.org/2000/xmlns/'; +my $def_ns_jcn = '{' . $xmlns_ns . '}'; ############################################################################## @@ -462,6 +463,7 @@ if($self->{opt}->{nsexpand}) { require XML::NamespaceSupport; $self->{nsup} = XML::NamespaceSupport->new(); + $self->{ns_prefix} = 'aaa'; } @@ -628,7 +630,13 @@ $opt->{cache} = [ $opt->{cache} ]; } - unless(exists($opt->{parseropts})) { + if(exists($opt->{parseropts})) { + if($^W) { + carp "Warning: " . + "'parseropts' is deprecated, contact the author if you need it"; + } + } + else { $opt->{parseropts} = [ ]; } @@ -969,17 +977,6 @@ my $nl = "\n"; - # Translate Clarkian names back to prefix:name form - - if($self->{nsup}) { - my($uri, $lname) = $self->{nsup}->parse_jclark_notation($name); - if($uri) { - my $prefix = $self->{nsup}->get_prefix($uri); - $name = "$prefix:$lname"; - } - } - - # Convert to XML if(ref($ref)) { @@ -1022,10 +1019,23 @@ # Scan for namespace declaration attributes my $nsdecls = ''; + my $default_ns_uri; if($self->{nsup}) { $ref = { %$ref }; # Make a copy before we mess with it $self->{nsup}->push_context(); + # Look for default namespace declaration first + + if(exists($ref->{$def_ns_jcn})) { + $self->{nsup}->declare_prefix('', $ref->{$def_ns_jcn}); + $nsdecls .= qq( xmlns="$ref->{$def_ns_jcn}"); + delete($ref->{$def_ns_jcn}); + } + $default_ns_uri = $self->{nsup}->get_uri(''); + + + # Then check all the other keys + foreach my $qname (keys(%$ref)) { my($uri, $lname) = $self->{nsup}->parse_jclark_notation($qname); if($uri) { @@ -1042,12 +1052,22 @@ foreach my $qname (keys(%$ref)) { my($uri, $lname) = $self->{nsup}->parse_jclark_notation($qname); if($uri) { - my $prefix = $self->{nsup}->get_prefix($uri); - unless($prefix) { - $prefix = $self->{nsup}->declare_prefix(undef, $uri); + if($default_ns_uri and $uri eq $default_ns_uri) { + $ref->{$lname} = $ref->{$qname}; + delete($ref->{$qname}); } - $ref->{"$prefix:$lname"} = $ref->{$qname}; - delete($ref->{$qname}); + else { + my $prefix = $self->{nsup}->get_prefix($uri); + unless($prefix) { + # $self->{nsup}->declare_prefix(undef, $uri); + # $prefix = $self->{nsup}->get_prefix($uri); + $prefix = $self->{ns_prefix}++; + $self->{nsup}->declare_prefix($prefix, $uri); + $nsdecls .= qq( xmlns:$prefix="$uri"); + } + $ref->{"$prefix:$lname"} = $ref->{$qname}; + delete($ref->{$qname}); + } } } } |