1--TEST--
2Serialization interaction between simplexml and dom for namespaces
3--EXTENSIONS--
4dom
5simplexml
6--FILE--
7<?php
8
9$dom = Dom\XMLDocument::createFromString('<root/>');
10$sxe = simplexml_import_dom($dom);
11
12$sxe->addAttribute('a:attr', 'value', 'urn:a');
13$sxe->addChild('b:child', 'value', 'urn:b');
14$sxe->addChild('foo', 'value2');
15$dom->documentElement->firstElementChild->appendChild($dom->createElementNS('urn:c', 'c:child'));
16
17echo "namespace c: ";
18var_dump($dom->documentElement->firstElementChild->firstElementChild->lookupNamespaceURI('c'));
19echo "namespace b: ";
20var_dump($dom->documentElement->firstElementChild->firstElementChild->lookupNamespaceURI('b'));
21echo "namespace a: ";
22var_dump($dom->documentElement->firstElementChild->firstElementChild->lookupNamespaceURI('a'));
23
24echo "=== serialize SimpleXML ===\n";
25
26echo $sxe->saveXML(), "\n";
27echo $sxe->foo->saveXML(), "\n";
28$sxe->asXML(__DIR__ . "/namespace_sxe_interaction1.xml");
29$sxe->foo->asXML(__DIR__ . "/namespace_sxe_interaction2.xml");
30echo file_get_contents(__DIR__ . "/namespace_sxe_interaction1.xml"), "\n";
31echo file_get_contents(__DIR__ . "/namespace_sxe_interaction2.xml"), "\n";
32
33echo "=== serialize DOM ===\n";
34
35echo $dom->saveXML(), "\n\n";
36
37echo "=== serialize imported DOM ===\n";
38
39// Importing should yield the exact same document
40$new_dom = Dom\XMLDocument::createEmpty();
41$new_dom->append($new_dom->importNode($dom->documentElement, true));
42echo $new_dom->saveXML(), "\n";
43
44?>
45--CLEAN--
46<?php
47@unlink(__DIR__ . "/namespace_sxe_interaction1.xml");
48@unlink(__DIR__ . "/namespace_sxe_interaction2.xml");
49?>
50--EXPECT--
51namespace c: string(5) "urn:c"
52namespace b: string(5) "urn:b"
53namespace a: NULL
54=== serialize SimpleXML ===
55<?xml version="1.0" encoding="UTF-8"?>
56<root xmlns:a="urn:a" a:attr="value"><b:child xmlns:b="urn:b">value<c:child xmlns:c="urn:c"/></b:child><foo>value2</foo></root>
57<foo>value2</foo>
58<?xml version="1.0" encoding="UTF-8"?>
59<root xmlns:a="urn:a" a:attr="value"><b:child xmlns:b="urn:b">value<c:child xmlns:c="urn:c"/></b:child><foo>value2</foo></root>
60<foo>value2</foo>
61=== serialize DOM ===
62<?xml version="1.0" encoding="UTF-8"?>
63<root xmlns:a="urn:a" a:attr="value"><b:child xmlns:b="urn:b">value<c:child xmlns:c="urn:c"/></b:child><foo>value2</foo></root>
64
65=== serialize imported DOM ===
66<?xml version="1.0" encoding="UTF-8"?>
67<root xmlns:a="urn:a" a:attr="value"><b:child xmlns:b="urn:b">value<c:child xmlns:c="urn:c"/></b:child><foo>value2</foo></root>
68