I'm loading xml using php (7.4) DomDocument loadXml() and then change some node text and then get the xml content using saveXml() method. The issue I'm facing is, in the modified content (got from saveXml()) the entity reference is removed.
The original xml content
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE section [
<!ENTITY % ent1 SYSTEM "isopub.ent">%ent1;
<!ENTITY % ent2 SYSTEM "isonum.ent">%ent2;
]>
<section>
...
The Code
$xml = file_get_contents('D:/temp/the-test.xml');
$doc = new \DOMDocument;
$doc->preserveWhiteSpace = true;
$doc->loadXml($xml);
$doc->encoding = 'utf-8';
$xml = $doc->saveXML();
Output
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE section [
<!ENTITY % ent1 SYSTEM "isopub.ent"> <---- Note the reference %ent1 is removed
<!ENTITY % ent2 SYSTEM "isonum.ent"> <---- Note the reference %ent2 is removed
]>
<section>
...
what I want is to retain the reference as same as the input.
what am I missing here