1--TEST-- 2Test writing Element::$innerHTML on XML documents 3--EXTENSIONS-- 4dom 5--FILE-- 6<?php 7 8$dom = DOM\XMLDocument::createEmpty(); 9$el = $dom->createElementNS('urn:a', 'root'); 10$dom->appendChild($el); 11$el->innerHTML = '<p>foo</p><p xmlns="">bar</p>'; 12echo $dom->saveXML(), "\n"; 13$el->innerHTML = ''; 14echo $dom->saveXML(), "\n"; 15$el->innerHTML = '&'; 16echo $dom->saveXML(), "\n"; 17$el->innerHTML = '<foo>'; 18echo $dom->saveXML(), "\n"; 19 20echo "----------------\n"; 21 22$dom = DOM\XMLDocument::createFromString('<root/>'); 23$child = $dom->documentElement->appendChild($dom->createElementNS('urn:a', 'child')); 24$child->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns', 'urn:b'); 25$child->innerHTML = '<default/>'; 26echo $dom->saveXML(), "\n"; 27var_dump($child->namespaceURI); 28var_dump($child->firstChild->namespaceURI); 29 30echo "----------------\n"; 31 32$dom = DOM\XMLDocument::createFromString(<<<XML 33<root xmlns="urn:a" xmlns:b="urn:b" xmlns:c="urn:c"> 34 <b:child a="none" b:b="b" c:c="c"/> 35 <c:child a="none" b:b="b" c:c="c"/> 36 <?pi ?> 37 <!-- comment --> 38 <child a="none" b:b="b" c:c="c"> 39 <![CDATA[ cdata ]]> 40 </child> 41</root> 42XML); 43$dom->documentElement->innerHTML = $dom->documentElement->innerHTML; 44echo $dom->saveXML(), "\n"; 45 46echo "----------------\n"; 47$dom->documentElement->innerHTML = <<<XML 48<child b:b="b" c:c="c"> 49 <b:child/> 50 <c:child/> 51</child> 52XML; 53echo $dom->saveXML(), "\n"; 54 55?> 56--EXPECT-- 57<?xml version="1.0" encoding="UTF-8"?> 58<root xmlns="urn:a"><p>foo</p><p xmlns="">bar</p></root> 59<?xml version="1.0" encoding="UTF-8"?> 60<root xmlns="urn:a"/> 61<?xml version="1.0" encoding="UTF-8"?> 62<root xmlns="urn:a">&</root> 63<?xml version="1.0" encoding="UTF-8"?> 64<root xmlns="urn:a"><foo></root> 65---------------- 66<?xml version="1.0" encoding="UTF-8"?> 67<root><child xmlns="urn:a"><default/></child></root> 68string(5) "urn:a" 69string(5) "urn:a" 70---------------- 71<?xml version="1.0" encoding="UTF-8"?> 72<root xmlns="urn:a" xmlns:b="urn:b" xmlns:c="urn:c"> 73 <b:child a="none" b:b="b" c:c="c"/> 74 <c:child a="none" b:b="b" c:c="c"/> 75 <?pi ?> 76 <!-- comment --> 77 <child xmlns="urn:a" a="none" b:b="b" c:c="c"> 78 <![CDATA[ cdata ]]> 79 </child> 80</root> 81---------------- 82<?xml version="1.0" encoding="UTF-8"?> 83<root xmlns="urn:a" xmlns:b="urn:b" xmlns:c="urn:c"><child b:b="b" c:c="c"> 84 <b:child/> 85 <c:child/> 86</child></root> 87