Commits

Anonymous committed 0d006b6

Added ns example for SAX tests
Fixed SAX for NS nodes

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
+<dromedaries xmlns="urn:camels" xmlns:mam="urn:mammals">
+    <species>Camelid</species>
+    <mam:legs>4</mam:legs>
+</dromedaries>

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");
   }
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.