1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Files
archived-php-src/ext/dom/tests/modern/spec/Document_importLegacyNode.phpt
Niels Dossche ff0a2cff05 Refactor implementation of DOM nodelists, named maps, and iterators
The code was really messy with lots of checks and inconsistencies.
This splits everything up into different functions and now everything is
relayed to a handler vtable.
2025-06-21 22:17:33 +02:00

71 lines
1.5 KiB
PHP

--TEST--
Document::importLegacyNode
--EXTENSIONS--
dom
--FILE--
<?php
$old = new DOMDocument;
$old->loadXML(<<<XML
<root>
<child xmlns="urn:a" a="b"/>
<child xmlns="urn:b" xmlns:c="urn:c" c:c="d"/>
<?pi?>
<!-- comment -->
<![CDATA[foo]]>
</root>
XML);
$new = Dom\XMLDocument::createEmpty();
$new->append($new->importLegacyNode($old->documentElement, true));
unset($old);
foreach ($new->getElementsByTagName('child') as $child) {
var_dump($child->attributes);
foreach ($child->attributes as $attr) {
echo "name: ";
var_dump($attr->name);
echo "prefix: ";
var_dump($attr->prefix);
echo "namespaceURI: ";
var_dump($attr->namespaceURI);
}
}
echo $new->saveXml(), "\n";
?>
--EXPECTF--
object(Dom\NamedNodeMap)#%d (1) {
["length"]=>
int(2)
}
name: string(5) "xmlns"
prefix: NULL
namespaceURI: string(29) "http://www.w3.org/2000/xmlns/"
name: string(1) "a"
prefix: NULL
namespaceURI: NULL
object(Dom\NamedNodeMap)#%d (1) {
["length"]=>
int(3)
}
name: string(5) "xmlns"
prefix: NULL
namespaceURI: string(29) "http://www.w3.org/2000/xmlns/"
name: string(7) "xmlns:c"
prefix: string(5) "xmlns"
namespaceURI: string(29) "http://www.w3.org/2000/xmlns/"
name: string(3) "c:c"
prefix: string(1) "c"
namespaceURI: string(5) "urn:c"
<?xml version="1.0" encoding="UTF-8"?>
<root>
<child xmlns="urn:a" a="b"/>
<child xmlns="urn:b" xmlns:c="urn:c" c:c="d"/>
<?pi ?>
<!-- comment -->
<![CDATA[foo]]>
</root>