Has anyone found a workaround for this; a workaround the fact that loadXML() completely replaces the existing document structure?
It's amazing what you find out after you've already made yourself look foolish.
$xmlStr = '<root><child_element>blah</child_element></root>';
$doc = new DOMDocument( '1.0', 'UTF-8' );
$docFragment = $doc->createDocumentFragment();
$docFragment->appendXML( $xmlStr ); // Why this isn't called also loadXML()
// I have no idea. It would make sense
// that it would be so as to maintain
// consistency in names of methods
// where it relates to functionality,
// particularly when that functionality is
// similar across classes.
$doc->appendChild( $doc->createProcessingInstruction( 'blah', 'blah' );
$doc->appendChild( $docFragment );
echo $doc->saveXML();