This is the result I’d like to have:
<?xml version="1.0" encoding="utf-8"?>
<types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
</types>
but using the straightforward solution:
$document = new DOMDocument('1.0', 'utf-8');
$schema = $document->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:schema');
$types = $document->createElement('types');
$types->appendChild($schema);
$document->appendChild($types);
echo $document->saveXML();
I only get this:
<?xml version="1.0" encoding="utf-8"?>
<types xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
</types>
What am I missing?
The problem is in order of appending children. Try this: