1--TEST-- 2HTMLDocument: XML-style namespace 3--EXTENSIONS-- 4dom 5--FILE-- 6<?php 7 8$dom = Dom\HTMLDocument::createFromString(<<<HTML 9<!DOCTYPE html> 10<html> 11<head> 12 <title>Test</title> 13</head> 14<body xmlns:foo="urn:hi"> 15 <foo:bar></foo:bar> 16</body> 17</html> 18HTML); 19 20echo "--- Namespaces ---\n"; 21$xpath = new Dom\XPath($dom); 22foreach ($xpath->query("//*[name()='body']//*") as $node) { 23 echo $node->nodeName, " ", $node->namespaceURI ?? "(NONE)", "\n"; 24 echo "prefix: \"", $node->prefix, "\"\n"; 25 foreach ($node->attributes as $attribute) { 26 echo " Attribute: ", $attribute->nodeName, " ", $attribute->namespaceURI ?? "(NONE)", "\n"; 27 } 28} 29 30echo "--- HTML serialization ---\n"; 31echo $dom->saveHtml(), "\n"; 32echo "--- XML serialization ---\n"; 33echo $dom->saveXml(); 34 35?> 36--EXPECT-- 37--- Namespaces --- 38FOO:BAR http://www.w3.org/1999/xhtml 39prefix: "" 40--- HTML serialization --- 41<!DOCTYPE html><html><head> 42 <title>Test</title> 43</head> 44<body xmlns:foo="urn:hi"> 45 <foo:bar></foo:bar> 46 47</body></html> 48--- XML serialization --- 49<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 50<!DOCTYPE html> 51<html xmlns="http://www.w3.org/1999/xhtml"><head> 52 <title>Test</title> 53</head> 54<body xmlns:foo="urn:hi"> 55 <foo:bar></foo:bar> 56 57</body></html> 58