To add/change the <?xml encoding
value in the output of saveHTML()
, you can set the encoding
property.
$xmldoc->load('test.xml');
$xmldoc->encoding= 'utf-8';
$xmldoc->save('test.xml');
However, as Artefacto said, in this case it's pointless. An XML file without an <?xml encoding
declaration or a UTF-16 BOM is definitely UTF-8 and all XML parsers will read it that way(*). You will gain nothing by adding an explicit encoding="utf-8"
parameter to the XML Declaration.
Whatever the method is you're using to test, it's not doing what you think it's doing. Maybe you're loading XML into a text editor and it's saving it out in a different encoding, or something? You need to look at where you're getting the strings from that are going into the DOM before you save it, and if they're not UTF-8 you need to convert them then.
(*: Well unless it's served via another protocol with a higher-priority charset specification method, like HTTP's Content-Type
header. But in that case the <?xml encoding
declaration is ignored anyway.)