1--TEST-- 2Element::setAttributeNS() 3--EXTENSIONS-- 4dom 5--FILE-- 6<?php 7 8require __DIR__ . "/dump_attr.inc"; 9 10$dom = Dom\HTMLDocument::createEmpty(); 11$container = $dom->appendChild($dom->createElement("container")); 12 13echo "--- xmlns attribute ---\n"; 14 15$container->setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:foo", "1"); 16echo $dom->saveHtml($container), "\n"; 17dumpAttrs($container); 18 19echo "--- name validation ---\n"; 20 21try { 22 $container->setAttributeNS("urn:a", "a:b:c", ""); 23} catch (DOMException $e) { 24 echo $e->getMessage(), "\n"; 25} 26 27echo "--- ns attributes with same namespace but different prefix ---\n"; 28 29$dom = Dom\HTMLDocument::createEmpty(); 30$container = $dom->appendChild($dom->createElement("container")); 31 32$container->setAttributeNS("urn:a", "x:foo", "1"); 33$container->setAttributeNS("urn:a", "y:foo", "2"); 34echo $dom->saveHtml($container), "\n"; 35dumpAttrs($container); 36 37echo "--- ns attributes with different namespace but same prefix ---\n"; 38 39$dom = Dom\HTMLDocument::createEmpty(); 40$container = $dom->appendChild($dom->createElement("container")); 41 42$container->setAttributeNS("urn:a", "x:foo", "1"); 43$container->setAttributeNS("urn:b", "x:foo", "2"); 44echo $dom->saveHtml($container), "\n"; 45dumpAttrs($container); 46 47?> 48--EXPECT-- 49--- xmlns attribute --- 50<container xmlns:foo="1"></container> 51Attr: xmlns:foo 52string(5) "xmlns" 53string(9) "xmlns:foo" 54string(29) "http://www.w3.org/2000/xmlns/" 55--- name validation --- 56Invalid Character Error 57--- ns attributes with same namespace but different prefix --- 58<container y:foo="2"></container> 59Attr: y:foo 60string(1) "y" 61string(5) "y:foo" 62string(5) "urn:a" 63--- ns attributes with different namespace but same prefix --- 64<container x:foo="1" x:foo="2"></container> 65Attr: x:foo 66string(1) "x" 67string(5) "x:foo" 68string(5) "urn:a" 69Attr: x:foo 70string(1) "x" 71string(5) "x:foo" 72string(5) "urn:b" 73