dom document save() encoding problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dcyphr314
Forum Newbie
Posts: 1
Joined: Fri Jul 15, 2011 2:16 pm

dom document save() encoding problem

Post by dcyphr314 »

I have been having trouble retaining the encoding type of an xml file. the file is opened fine, changes are made fine, then the file is saved fine. However, somewhere in this process the character encoding changes. Special characters written as say: & #174; end up looking like this: ®

Code: Select all

$dom = new DOMDocument('1.0', 'UTF-8');
$dom->load('/rawInventory.xml');

$xpath = new DOMXPath($dom);
$sohs = $xpath->query('/ac//soh');

//changes are made then the file is saved:

$dom->save('/rawInventory.xml');
why would the encoding change on save if it is correctly declared when the dom document is made?
Post Reply