0

simplexml_load_string()配列から(データベースから)XMLを読んでいます。

XML に引用符が含まれるまでは問題ありません。simplexml が XML 解析エラーを報告し始めます。

  1. XMLファイルに変更""ました->パーサーエラー。
  2. --> parser-error の"ように XML でエスケープしました。\"
  3. --> すべて問題ありませんが、!'の代わりに使用しました。""
  4. それで、""into CDATA--> 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']));

エラー - の&#34;代わりに":

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
4

2 に答える 2

0

XML に相当するエンティティの引用符を置き換えてみてください。&#34;

str_replace('"', '&#34;', $xml);
于 2013-02-12T15:03:02.320 に答える