Anonymous avatar Anonymous committed fb2b3e0

Added Files:
t/10ns.t
+ namespace tests

Comments (0)

Files changed (1)

+use Test;
+BEGIN { plan tests=>21; }
+END {ok(0) unless $loaded;}
+use XML::LibXML;
+$loaded = 1;
+ok($loaded);
+
+my $xml = <<EOX;
+<a xmlns:b="http://whatever"
+><x b:href="out.xml"
+/><b:c/></a>
+EOX
+
+my $doc = XML::LibXML->new()->parse_string($xml);
+my $docElem = $doc->getDocumentElement();
+my $child = ($docElem->getChildnodes())[0];
+
+ok($child->hasAttributeNS('http://whatever','href'));
+
+ok(!defined($child->getAttribute('bogus')));
+
+ok(defined($child->getLocalName()));
+ok(!defined($child->getPrefix()));
+ok(!defined($child->getNamespaceURI()));
+
+my $val = $child->getAttributeNS('http://whatever','href');
+ok($val,'out.xml');
+
+$child = ($docElem->getChildnodes())[1];
+ok($child->getLocalName() eq 'c');
+ok($child->getPrefix() eq 'b');
+ok($child->getNamespaceURI() eq 'http://whatever');
+
+$child->removeAttributeNS('http://whatever','href');
+ok(!$child->hasAttributeNS('http://whatever','href'));
+
+my $added_attr = 'added.xml';
+$child->setAttributeNS('http://whatever', 'b2:href', $added_attr);
+
+ok($child->hasAttributeNS('http://whatever','href')
+   && $child->getAttributeNS('http://whatever','href') eq $added_attr);
+
+my @bytag = $docElem->getElementsByTagName('x');
+ok(scalar(@bytag) == 1);
+
+@bytag = $docElem->getElementsByTagNameNS('http://whatever','c');
+ok(scalar(@bytag) == 1);
+
+my $tag = pop @bytag;
+ok($tag->getLocalName() eq 'c');
+ok($tag->getPrefix() eq 'b');
+ok($tag->getNamespaceURI() eq 'http://whatever');
+
+my $newElem = $doc->createElementNS('http://whatever','d:newElem');
+ok(defined($newElem));
+ok($newElem->getLocalName, 'newElem');
+ok($newElem->getPrefix, 'd');
+ok($newElem->getNamespaceURI, 'http://whatever');
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.