I have some problems using xml. I know this is a comon question, but the answers i found didn't fix my problem. The problem is that when I add é or ä or another special char to my xml file, with php domdocument, it saves the é as xE9 and the ä as xE4. I don't know if this is ok but when I want to show the output it shows question marks at this places. I have tried alot. Like removing and adding the encoding in de xml header in the php domdocument. I also tried using file_get_contents and use php utf-8_decode to get the xml. I tried using iso intead, but nothing solved my problem. Instead I got php xml parse errors sometimes. I must do something wrong, but what? Thats my question and how I can solve this problem. My xml file looks like this: the xE9 and the xE4 have black backgrounds.
<?xml version="1.0" encoding="UTF-8"?>
<root>
<row id="1">
<question>blah</question>
<answer>blah</answer>
</row>
<row id="2">
<question>xE9</question>
<answer>xE4</answer>
</row>
</root>
and a part of my php xml class
function __construct($filePath) {
$this->file = $filePath;
$this->label = array('Vraag', 'Antwoord');
$xmlStr = file_get_contents($filePath);
$xmlStr = utf8_decode($xmlStr);
$this->xmlDoc = new DOMDocument('1.0', 'UTF-8');
$this->xmlDoc->preserveWhiteSpace = false;
$this->xmlDoc->formatOutput = true;
//$this->xmlDoc->load($filePath);
$this->xmlDoc->loadXML($xmlStr);
}
this is the add new row function
//creates new xml row and saves it in xml file
function addNewRow($question, $answer) {
$nextAttr = $this->getNextRowId();
$parentNode = $this->xmlDoc->documentElement;
$rowNode = $this->xmlDoc->createElement('row');
$rowNode = $parentNode->appendChild($rowNode);
$rowNode->setAttribute('id', $nextAttr);
$q = $this->xmlDoc->createElement('question');
$q = $rowNode->appendChild($q);
$qText = $this->xmlDoc->createTextNode($question);
$qText = $q->appendChild($qText);
$a = $this->xmlDoc->createElement('answer');
$a = $rowNode->appendChild($a);
$aText = $this->xmlDoc->createTextNode($answer);
$aText = $a->appendChild($aText);
$this->xmlDoc->save($this->file);
}
everything works fine till I add spcial chars. Those are shown as questionmarks.