diff --git a/src/Xml/Dom/Document.php b/src/Xml/Dom/Document.php index be5ae06..f3e3ff6 100644 --- a/src/Xml/Dom/Document.php +++ b/src/Xml/Dom/Document.php @@ -15,7 +15,6 @@ use function Psl\Vec\map; use function VeeWee\Xml\Dom\Configurator\loader; use function VeeWee\Xml\Dom\Loader\xml_file_loader; -use function VeeWee\Xml\Dom\Loader\xml_node_loader; use function VeeWee\Xml\Dom\Loader\xml_string_loader; use function VeeWee\Xml\Dom\Locator\document_element; use function VeeWee\Xml\Dom\Mapper\xml_string; @@ -80,7 +79,9 @@ public static function fromXmlString(string $xml, callable ...$configurators): s public static function fromXmlNode(DOMNode $node, callable ...$configurators): self { return self::configure( - loader(xml_node_loader($node)), + loader(xml_string_loader( + xml_string()($node) + )), ...$configurators ); } diff --git a/tests/Xml/Dom/DocumentTest.php b/tests/Xml/Dom/DocumentTest.php index 262dc80..e64f047 100644 --- a/tests/Xml/Dom/DocumentTest.php +++ b/tests/Xml/Dom/DocumentTest.php @@ -11,7 +11,9 @@ use VeeWee\Xml\Dom\Document; use VeeWee\Xml\Dom\Traverser\Action; use VeeWee\Xml\Dom\Traverser\Visitor\AbstractVisitor; +use VeeWee\Xml\Dom\Traverser\Visitor\RemoveNamespaces; use function Psl\Fun\identity; +use function VeeWee\Xml\Dom\Configurator\traverse; use function VeeWee\Xml\Dom\Configurator\trim_spaces; use function VeeWee\Xml\Dom\Configurator\utf8; use function VeeWee\Xml\Dom\Locator\document_element; @@ -65,7 +67,7 @@ public function test_it_can_add_various_configurators(): void } - public function test_it_can_create_a_document_from_xml_nod(): void + public function test_it_can_create_a_document_from_xml_node(): void { $source = new DOMDocument(); $source->loadXML($xml = ''); @@ -78,6 +80,23 @@ public function test_it_can_create_a_document_from_xml_nod(): void static::assertXmlStringEqualsXmlString($xml, $doc->toXmlString()); } + /** + * @see https://github.com/php/php-src/issues/12616 + */ + public function test_it_can_create_a_document_from_xml_node_with_removed_namespaces(): void + { + $source = Document::fromXmlString( + '', + traverse(RemoveNamespaces::all()) + ); + + $doc = Document::fromXmlNode( + $source->map(document_element()), + identity() + ); + + static::assertXmlStringEqualsXmlString('', $doc->toXmlString()); + } public function test_it_can_create_a_document_from_xml_file(): void {