1--TEST-- 2DOMDocument::importNode() with attribute prefix name conflict 3--EXTENSIONS-- 4dom 5--FILE-- 6<?php 7 8echo "--- Non-default namespace test case without a default namespace in the destination ---\n"; 9 10$dom1 = new DOMDocument(); 11$dom2 = new DOMDocument(); 12$dom1->loadXML('<?xml version="1.0"?><container xmlns:foo="http://php.net" foo:bar="yes"/>'); 13$dom2->loadXML('<?xml version="1.0"?><container xmlns:foo="http://php.net/2"/>'); 14$attribute = $dom1->documentElement->getAttributeNode('foo:bar'); 15$imported = $dom2->importNode($attribute); 16$dom2->documentElement->setAttributeNodeNS($imported); 17 18echo $dom1->saveXML(); 19echo $dom2->saveXML(); 20 21echo "--- Non-default namespace test case with a default namespace in the destination ---\n"; 22 23$dom1 = new DOMDocument(); 24$dom2 = new DOMDocument(); 25$dom1->loadXML('<?xml version="1.0"?><container xmlns:foo="http://php.net" foo:bar="yes"/>'); 26$dom2->loadXML('<?xml version="1.0"?><container xmlns="http://php.net" xmlns:foo="http://php.net/2"/>'); 27$attribute = $dom1->documentElement->getAttributeNode('foo:bar'); 28$imported = $dom2->importNode($attribute); 29$dom2->documentElement->setAttributeNodeNS($imported); 30 31echo $dom1->saveXML(); 32echo $dom2->saveXML(); 33 34echo "--- Default namespace test case ---\n"; 35 36// We don't expect the namespace to be imported because default namespaces on the same element don't apply to attributes 37// but the attribute should be imported 38$dom1 = new DOMDocument(); 39$dom2 = new DOMDocument(); 40$dom1->loadXML('<?xml version="1.0"?><container xmlns="http://php.net" bar="yes"/>'); 41$dom2->loadXML('<?xml version="1.0"?><container xmlns="http://php.net/2"/>'); 42$attribute = $dom1->documentElement->getAttributeNode('bar'); 43$imported = $dom2->importNode($attribute); 44$dom2->documentElement->setAttributeNodeNS($imported); 45 46echo $dom1->saveXML(); 47echo $dom2->saveXML(); 48 49?> 50--EXPECT-- 51--- Non-default namespace test case without a default namespace in the destination --- 52<?xml version="1.0"?> 53<container xmlns:foo="http://php.net" foo:bar="yes"/> 54<?xml version="1.0"?> 55<container xmlns:foo="http://php.net/2" xmlns:default="http://php.net" default:bar="yes"/> 56--- Non-default namespace test case with a default namespace in the destination --- 57<?xml version="1.0"?> 58<container xmlns:foo="http://php.net" foo:bar="yes"/> 59<?xml version="1.0"?> 60<container xmlns="http://php.net" xmlns:foo="http://php.net/2" xmlns:default="http://php.net" default:bar="yes"/> 61--- Default namespace test case --- 62<?xml version="1.0"?> 63<container xmlns="http://php.net" bar="yes"/> 64<?xml version="1.0"?> 65<container xmlns="http://php.net/2" bar="yes"/> 66