simplexml_load_string()
配列から(データベースから)XMLを読んでいます。
XML に引用符が含まれるまでは問題ありません。simplexml が XML 解析エラーを報告し始めます。
- XMLファイルに変更
"
し"
ました->パーサーエラー。 - --> parser-error の
"
ように XML でエスケープしました。\"
- --> すべて問題ありませんが、!
'
の代わりに使用しました。"
"
- それで、
""
intoCDATA
--> parser-error の部分をもう一度含めました!`
XML スニペット:
<prepare var="%vorfall%" label="Bezeichnen Sie den Vorfall">
<![CDATA["Vorfall beim Reiten..."]]>
</prepare>
PHP スニペット:
$rxml=simplexml_load_string(utf8_encode($test['tsValues']));
エラー - の"
代わりに"
:
Warning: simplexml_load_string(): Entity: line 16: parser error : attributes construct error in /Applications/MAMP/htdocs/_testcenter/testcenter.php on line 97
Warning: simplexml_load_string(): <prepare var=""Unfall beim Reiten, Rocky geht durch"" label="Bezeichnen Sie den in /Applications/MAMP/htdocs/_testcenter/testcenter.php on line 97
Warning: simplexml_load_string(): ^ in /Applications/MAMP/htdocs/_testcenter/testcenter.php on line 97
Warning: simplexml_load_string(): Entity: line 16: parser error : Couldn't find end of Start Tag prepare line 16 in /Applications/MAMP/htdocs/_testcenter/testcenter.php on line 97
Warning: simplexml_load_string(): <prepare var=""Unfall beim Reiten, Rocky geht durch"" label="Bezeichnen Sie den in /Applications/MAMP/htdocs/_testcenter/testcenter.php on line 97
Warning: simplexml_load_string(): ^ in /Applications/MAMP/htdocs/_testcenter/testcenter.php on line 97
更新: もう一度確認してください。ここで問題が発生しています - PHP:
$txml=file_get_contents("$path_test/".$test['tbTestFile']);
$rxml=simplexml_load_string($test['tsValues']);
// replacing parts of $txml with content containing the famous "" from $rxml
foreach ($rxml->xpath('//prepare') as $prep) {
$txml=str_replace($prep['var'],$prep,$txml);
}
$txml=simplexml_load_string($txml); // this is line 97