Another option, if you have some control over the documents to be passed to DOMDocument is to use HTML entities (   ) or unicode characters ( U+00A0 ) instead of named characters ( ).
Assuming the following documents:
Document 1 ( test_1.xml )
<?xml version="1.0" encoding="UTF-8"?>
<root>
<element>this line has a space ( )</element>
<element>this line has a non breakin space ( )</element>
<element>this line has an integral symbol (∫)</element>
</root>
Document 2 ( test_2.xml )
<?xml version="1.0" encoding="UTF-8"?>
<root>
<element>this line has a space ( )</element>
<element>this line has a non breakin space ( )</element>
<element>this line has an integral symbol (∫)</element>
</root>
Document 3 ( test_3.xml )
<?xml version="1.0" encoding="UTF-8"?>
<root>
<element>this line has a space ( )</element>
<element>this line has a non breakin space (U+00A0)</element>
<element>this line has an integral symbol (U+222B)</element>
</root>
And a php file that loads those documents: ( index.php )
<?php
declare(strict_types=1);
$xmlDoc = new DOMDocument();
$xml_file = file_get_contents( "test_2.xml" );
$xmlDoc->loadXML( $xml_file );
?>
The first document will generate warnings like the following:
Warning: DOMDocument::loadXML(): Entity 'nbsp' not defined in Entity, line: 4 in /path/to/file/index.php on line 5
Warning: DOMDocument::loadXML(): Entity 'int' not defined in Entity, line: 5 in /path/to/file/index.php on line 5
But documents 2 and 3 will be parsed fine.
Reference: