<?php
$aDOM = new DOMDocument();
$aDOM->loadXML('<f2f:o xmlns:f2f=" http://friend2friend.net " xmlns:default="default"><default:i xmlns="default"><f2f:watch-me/></default:i></f2f:o>');
echo 'Initial DOM is '.$aDOM->saveXML().chr(13);
$newNode= $aDOM->createElementNS(" http://friend2friend.net ", 'newnode');
$newNode->appendChild($aDOM->documentElement);
echo 'Appending the document Element to f2f:newnode, it all looks OK: '.chr(13).$aDOM->saveXML($newNode).chr(13).chr(13);
$aDOM->appendChild($newNode);
echo 'But adding <f2f:newnode> back as the documentElement changes a namespace '.$aDOM->saveXML();
Warning: DOMDocument::loadXML(): xmlns:f2f: ' http://friend2friend.net ' is not a valid URI in Entity, line: 1 in /in/93fde on line 3
Notice: DOMDocument::loadXML(): xmlns: URI default is not absolute in Entity, line: 1 in /in/93fde on line 3
Initial DOM is <?xml version="1.0"?>
<f2f:o xmlns:f2f=" http://friend2friend.net " xmlns:default="default"><default:i xmlns="default"><f2f:watch-me/></default:i></f2f:o>
Appending the document Element to f2f:newnode, it all looks OK:
<newnode xmlns=" http://friend2friend.net "><f2f:o xmlns:f2f=" http://friend2friend.net " xmlns:default="default"><default:i xmlns="default"><f2f:watch-me/></default:i></f2f:o></newnode>
But adding <f2f:newnode> back as the documentElement changes a namespace <?xml version="1.0"?>
<newnode xmlns=" http://friend2friend.net " xmlns:default="default"><o xmlns:f2f=" http://friend2friend.net " xmlns:default="default"><default:i xmlns="default"><watch-me/></default:i></o></newnode>
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Warning: DOMDocument::loadXML(): xmlns:f2f: ' http://friend2friend.net ' is not a valid URI in Entity, line: 1 in /in/93fde on line 3
Notice: DOMDocument::loadXML(): xmlns: URI default is not absolute in Entity, line: 1 in /in/93fde on line 3
Initial DOM is <?xml version="1.0"?>
<f2f:o xmlns:f2f=" http://friend2friend.net " xmlns:default="default"><default:i xmlns="default"><f2f:watch-me/></default:i></f2f:o>
Appending the document Element to f2f:newnode, it all looks OK:
<newnode xmlns=" http://friend2friend.net "><f2f:o xmlns:f2f=" http://friend2friend.net " xmlns:default="default"><default:i xmlns="default"><f2f:watch-me/></default:i></f2f:o></newnode>
But adding <f2f:newnode> back as the documentElement changes a namespace <?xml version="1.0"?>
<newnode xmlns=" http://friend2friend.net " xmlns:default="default"><o xmlns:f2f=" http://friend2friend.net " xmlns:default="default"><default:i xmlns="default"><watch-me/></default:i></o></newnode>
Output for 8.1.21 - 8.1.24, 8.2.8 - 8.2.11
Warning: DOMDocument::loadXML(): xmlns:f2f: ' http://friend2friend.net ' is not a valid URI in Entity, line: 1 in /in/93fde on line 3
Notice: DOMDocument::loadXML(): xmlns: URI default is not absolute in Entity, line: 1 in /in/93fde on line 3
Initial DOM is <?xml version="1.0"?>
<f2f:o xmlns:f2f=" http://friend2friend.net " xmlns:default="default"><default:i xmlns="default"><f2f:watch-me/></default:i></f2f:o>
Appending the document Element to f2f:newnode, it all looks OK:
<newnode xmlns=" http://friend2friend.net "><f2f:o xmlns:f2f=" http://friend2friend.net " xmlns:default="default"><default:i xmlns="default"><f2f:watch-me/></default:i></f2f:o></newnode>
But adding <f2f:newnode> back as the documentElement changes a namespace <?xml version="1.0"?>
<newnode xmlns=" http://friend2friend.net "><f2f:o xmlns:f2f=" http://friend2friend.net " xmlns:default="default"><default:i xmlns="default"><f2f:watch-me/></default:i></f2f:o></newnode>
Output for 7.3.32 - 7.3.33
Warning: DOMDocument::loadXML(): xmlns:f2f: ' http://friend2friend.net ' is not a valid URI in Entity, line: 1 in /in/93fde on line 3
Initial DOM is <?xml version="1.0"?>
<f2f:o xmlns:f2f=" http://friend2friend.net " xmlns:default="default"><default:i xmlns="default"><f2f:watch-me/></default:i></f2f:o>
Appending the document Element to f2f:newnode, it all looks OK:
<newnode xmlns=" http://friend2friend.net "><f2f:o xmlns:f2f=" http://friend2friend.net " xmlns:default="default"><default:i xmlns="default"><f2f:watch-me/></default:i></f2f:o></newnode>
But adding <f2f:newnode> back as the documentElement changes a namespace <?xml version="1.0"?>
<newnode xmlns=" http://friend2friend.net " xmlns:default="default"><o xmlns:f2f=" http://friend2friend.net " xmlns:default="default"><default:i xmlns="default"><watch-me/></default:i></o></newnode>