【发布时间】:2020-07-07 19:44:52
【问题描述】:
我正在创建一个脚本来使用 DOM 文档将 json 解析为 XML。当我想将 放在 createElement 部分的节点值内时遇到问题。 < 和 > 被转换为 < 和 >,我希望它保持原样。
我怎样才能让它保持原样?
这是我当前的代码:
$dom->encoding = 'utf-8';
$dom->xmlVersion = '1.0';
$dom->formatOutput = true;
$root = $dom->createElement('questions', "<![CDATA[what animal walk above the wave?]]>");
....
$dom->save('file.xml');
我的 XML 结果:
<question><![CDATA[what animal walk above the wave?]]></question>
我期待:
<question><![CDATA[what animal walk above the wave?]]></question>
【问题讨论】: