If you're working with an existing XML file that contains an entity definition with an external reference like this one:
[
<!ENTITY % all.entities SYSTEM "all-entities.ent">
%all.entities;
]>
Be warned that DOMDocument->save() will expand this to include all definitions in all referenced entities file(s) when it writes the file. In other words, the same section of your saved file would now look something like this:
<!ENTITY % all.entities SYSTEM "all-entities.ent">
<!--
This file names all the entity files needed by .xml files in the
current directory. All ENTITY declarations should be given
first, followed by references to the those entities.
--><!ENTITY % fixedchars.entities SYSTEM "../common/fixedchars.ent">
<!ENTITY % urls.entities SYSTEM "../refman-common/urls.ent">
<!ENTITY % phrases.entities SYSTEM "../common/phrases.ent">
<!ENTITY % ndb.entities SYSTEM "ndb.en.ent">
<!ENTITY minus "–"><!-- 2013 is actually Unicode for ndash -->
<!ENTITY Oslash "Ø">
<!ENTITY macr "¯">
<!ENTITY auml "ä">
[etc.]
I've not found a way to keep this from occurring.