|
| 1 | +--TEST-- |
| 2 | +Serialization interaction between simplexml and dom for namespaces |
| 3 | +--EXTENSIONS-- |
| 4 | +dom |
| 5 | +simplexml |
| 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 | + |
| 17 | +echo "namespace c: "; |
| 18 | +var_dump($dom->documentElement->firstElementChild->firstElementChild->lookupNamespaceURI('c')); |
| 19 | +echo "namespace b: "; |
| 20 | +var_dump($dom->documentElement->firstElementChild->firstElementChild->lookupNamespaceURI('b')); |
| 21 | +echo "namespace a: "; |
| 22 | +var_dump($dom->documentElement->firstElementChild->firstElementChild->lookupNamespaceURI('a')); |
| 23 | + |
| 24 | +echo "=== serialize SimpleXML ===\n"; |
| 25 | + |
| 26 | +echo $sxe->saveXML(), "\n"; |
| 27 | + |
| 28 | +echo "=== serialize DOM ===\n"; |
| 29 | + |
| 30 | +echo $dom->saveXML(), "\n\n"; |
| 31 | + |
| 32 | +echo "=== serialize imported DOM ===\n"; |
| 33 | + |
| 34 | +// Importing should yield the exact same document |
| 35 | +$new_dom = Dom\XMLDocument::createEmpty(); |
| 36 | +$new_dom->append($new_dom->importNode($dom->documentElement, true)); |
| 37 | +echo $new_dom->saveXML(), "\n"; |
| 38 | + |
| 39 | +?> |
| 40 | +--EXPECT-- |
| 41 | +namespace c: string(5) "urn:c" |
| 42 | +namespace b: string(5) "urn:b" |
| 43 | +namespace a: NULL |
| 44 | +=== serialize SimpleXML === |
| 45 | +<?xml version="1.0" encoding="UTF-8"?> |
| 46 | +<root xmlns:a="urn:a" a:attr="value"><b:child xmlns:b="urn:b">value<c:child xmlns:c="urn:c"/></b:child></root> |
| 47 | +=== serialize DOM === |
| 48 | +<?xml version="1.0" encoding="UTF-8"?> |
| 49 | +<root xmlns:a="urn:a" a:attr="value"><b:child xmlns:b="urn:b">value<c:child xmlns:c="urn:c"/></b:child></root> |
| 50 | + |
| 51 | +=== serialize imported DOM === |
| 52 | +<?xml version="1.0" encoding="UTF-8"?> |
| 53 | +<root xmlns:a="urn:a" a:attr="value"><b:child xmlns:b="urn:b">value<c:child xmlns:c="urn:c"/></b:child></root> |
0 commit comments