1--TEST--
2HTMLDocument: Predefined namespaces
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>
15    <svg width="100" height="100" viewBox="0 0 4 2">
16        <rect id="rectangle" x="10" y="20" width="90" height="60">
17        </rect>
18    </svg>
19    <div>
20        <p>foo</p>
21    </div>
22    <math>
23        <!-- svg should be in the mathml namespace -->
24        <mtable id="table"><svg></svg></mtable>
25    </math>
26</body>
27</html>
28HTML);
29
30echo "--- Namespaces ---\n";
31$xpath = new Dom\XPath($dom);
32foreach ($xpath->query("//*[name()='body']//*") as $node) {
33    echo $node->nodeName, " ", $node->namespaceURI ?? "(NONE)", "\n";
34    foreach ($node->attributes as $attribute) {
35        echo "  Attribute: ", $attribute->nodeName, " ", $attribute->namespaceURI ?? "(NONE)", "\n";
36    }
37}
38
39echo "--- HTML serialization ---\n";
40echo $dom->saveHtml(), "\n";
41echo "--- XML serialization ---\n";
42echo $dom->saveXml();
43
44?>
45--EXPECT--
46--- Namespaces ---
47svg http://www.w3.org/2000/svg
48  Attribute: width (NONE)
49  Attribute: height (NONE)
50  Attribute: viewbox (NONE)
51rect http://www.w3.org/2000/svg
52  Attribute: id (NONE)
53  Attribute: x (NONE)
54  Attribute: y (NONE)
55  Attribute: width (NONE)
56  Attribute: height (NONE)
57DIV http://www.w3.org/1999/xhtml
58P http://www.w3.org/1999/xhtml
59math http://www.w3.org/1998/Math/MathML
60mtable http://www.w3.org/1998/Math/MathML
61  Attribute: id (NONE)
62svg http://www.w3.org/1998/Math/MathML
63--- HTML serialization ---
64<!DOCTYPE html><html><head>
65    <title>Test</title>
66</head>
67<body>
68    <svg width="100" height="100" viewbox="0 0 4 2">
69        <rect id="rectangle" x="10" y="20" width="90" height="60">
70        </rect>
71    </svg>
72    <div>
73        <p>foo</p>
74    </div>
75    <math>
76        <!-- svg should be in the mathml namespace -->
77        <mtable id="table"><svg></svg></mtable>
78    </math>
79
80</body></html>
81--- XML serialization ---
82<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
83<!DOCTYPE html>
84<html xmlns="http://www.w3.org/1999/xhtml"><head>
85    <title>Test</title>
86</head>
87<body>
88    <svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewbox="0 0 4 2">
89        <rect id="rectangle" x="10" y="20" width="90" height="60">
90        </rect>
91    </svg>
92    <div>
93        <p>foo</p>
94    </div>
95    <math xmlns="http://www.w3.org/1998/Math/MathML">
96        <!-- svg should be in the mathml namespace -->
97        <mtable id="table"><svg/></mtable>
98    </math>
99
100</body></html>
101