Anonymous avatar Anonymous committed c78aae4

Modified Files:
lib/XML/LibXML/SAX/Parser.pm
o namespace handling for elements

Comments (0)

Files changed (1)

lib/XML/LibXML/SAX/Parser.pm

     my ($self, $element) = @_;
 
     my $attribs = {};
-    my @ns_maps;
+    my @ns_maps = $element->getNamespaces;
+
+    foreach my $ns (@ns_maps) {
+        $self->start_prefix_mapping(
+            {
+                NamespaceURI => $ns->href,
+                Prefix       => ( defined $ns->localname  ? $ns->localname : ''),
+            }
+        );
+    }
 
     foreach my $attr ($element->attributes) {
         my $key;
         # warn("Attr: $attr -> ", $attr->getName, " = ", $attr->getData, "\n");
+        # this isa dump thing...
         if ($attr->isa('XML::LibXML::Namespace')) {
             # TODO This needs fixing modulo agreeing on what
             # is the right thing to do here.
                     Prefix => $p,
                     LocalName => $localname,
                 };
-            push @ns_maps, $attribs->{$key};
+            # push @ns_maps, $attribs->{$key};
         }
         else {
             my $ns = $attr->namespaceURI || '';
         LocalName => $element->localname,
     };
 
-    foreach my $ns (@ns_maps) {
-        $self->start_prefix_mapping(
-            {
-                NamespaceURI => $ns->{Value},
-                Prefix => (($ns->{LocalName} eq 'xmlns') ? '' : $ns->{LocalName}),
-            }
-        );
-    }
-
     $self->start_element($node);
 
     foreach my $child ($element->childNodes) {
     delete $end_node->{Attributes};
 
     $self->end_element($end_node);
-    
+
     foreach my $ns (@ns_maps) {
         $self->end_prefix_mapping(
             {
-                NamespaceURI => $ns->{Value},
-                Prefix => (($ns->{LocalName} eq 'xmlns') ? '' : $ns->{LocalName}),
+                NamespaceURI => $ns->href,
+                Prefix       => ( defined $ns->localname  ? $ns->localname : ''),
             }
         );
     }
-
 }
 
 1;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.