1--TEST--
2Document::importLegacyNode
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8$old = new DOMDocument;
9$old->loadXML(<<<XML
10<root>
11    <child xmlns="urn:a" a="b"/>
12    <child xmlns="urn:b" xmlns:c="urn:c" c:c="d"/>
13    <?pi?>
14    <!-- comment -->
15    <![CDATA[foo]]>
16</root>
17XML);
18
19$new = Dom\XMLDocument::createEmpty();
20$new->append($new->importLegacyNode($old->documentElement, true));
21
22unset($old);
23
24foreach ($new->getElementsByTagName('child') as $child) {
25    var_dump($child->attributes);
26    foreach ($child->attributes as $attr) {
27        echo "name: ";
28        var_dump($attr->name);
29        echo "prefix: ";
30        var_dump($attr->prefix);
31        echo "namespaceURI: ";
32        var_dump($attr->namespaceURI);
33    }
34}
35
36echo $new->saveXml(), "\n";
37
38?>
39--EXPECT--
40object(Dom\NamedNodeMap)#5 (1) {
41  ["length"]=>
42  int(2)
43}
44name: string(5) "xmlns"
45prefix: NULL
46namespaceURI: string(29) "http://www.w3.org/2000/xmlns/"
47name: string(1) "a"
48prefix: NULL
49namespaceURI: NULL
50object(Dom\NamedNodeMap)#3 (1) {
51  ["length"]=>
52  int(3)
53}
54name: string(5) "xmlns"
55prefix: NULL
56namespaceURI: string(29) "http://www.w3.org/2000/xmlns/"
57name: string(7) "xmlns:c"
58prefix: string(5) "xmlns"
59namespaceURI: string(29) "http://www.w3.org/2000/xmlns/"
60name: string(3) "c:c"
61prefix: string(1) "c"
62namespaceURI: string(5) "urn:c"
63<?xml version="1.0" encoding="UTF-8"?>
64<root>
65    <child xmlns="urn:a" a="b"/>
66    <child xmlns="urn:b" xmlns:c="urn:c" c:c="d"/>
67    <?pi ?>
68    <!-- comment -->
69    <![CDATA[foo]]>
70</root>
71