Commits

Anonymous committed 0d006b6

Added ns example for SAX tests
Fixed SAX for NS nodes

  • Participants
  • Parent commits 8719ca5

Comments (0)

Files changed (4)

 example/complex/complex.dtd
 example/complex/dtd/f.dtd
 example/complex/dtd/g.dtd
+example/ns.xml
 t/01basic.t
 t/02parsestring.t
 t/03parsefile.t

File example/ns.xml

+<dromedaries xmlns="urn:camels" xmlns:mam="urn:mammals">
+    <species>Camelid</species>
+    <mam:legs>4</mam:legs>
+</dromedaries>

File lib/XML/LibXML/SAX/Parser.pm

     
     foreach my $attr ($element->getAttributes) {
         my $key;
-        if (my $ns = $attr->getNamespaceURI) {
+        if ($attr->isa('XML::LibXML::Namespace')) {
+            $key = "{http://www.w3.org/2000/xmlns/}" . $attr->getName;
+        }
+        elsif (my $ns = $attr->getNamespaceURI) {
             $key = "{$ns}".$attr->getLocalName;
         }
         else {
 use Test;
-BEGIN { plan tests => 33 }
+BEGIN { plan tests => 38 }
 use XML::LibXML;
 use XML::LibXML::SAX::Parser;
 use XML::LibXML::SAX::Builder;
 ok($parser);
 $parser->parse_uri("example/dromeds.xml");
 
+$parser->parse_uri("example/ns.xml");
+
 ########### Helper class #############
 
 package SAXTester;
 
 sub start_element {
   my ($self, $el) = @_;
-  ok($el->{Name}, qr{^(dromedaries|species|humps|disposition)$});
+  ok($el->{LocalName}, qr{^(dromedaries|species|humps|disposition|legs)$});
   foreach my $attr (keys %{$el->{Attributes}}) {
     # warn("Attr: $attr = $el->{Attributes}->{$attr}\n");
   }