所以,我有这个代码在我的XML文件中搜索特定节点,取消设置现有节点并插入具有正确数据的全新子节点.有没有办法使用simpleXML将这些新数据保存在实际的XML文件中?如果没有,还有另一种有效的方法吗?
public function hint_insert() {
foreach($this->hints as $key => $value) {
$filename = $this->get_qid_filename($key);
echo "$key - $filename - $value[0]<br>";
//insert hint within right node using simplexml
$xml = simplexml_load_file($filename);
foreach ($xml->PrintQuestion as $PrintQuestion) {
unset($xml->PrintQuestion->content->multichoice->feedback->hint->Passage);
$xml->PrintQuestion->content->multichoice->feedback->hint->addChild('Passage', $value[0]);
echo("<pre>" . print_r($PrintQuestion) . "</pre>");
return;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我的浏览器告诉我:
\n\nerror on line 2 at column 308899: Entity 'ntilde' not defined\nRun Code Online (Sandbox Code Playgroud)\n\n具体行在我的 xml 中为:
\n\n<LastName>Treviño</LastName>\nRun Code Online (Sandbox Code Playgroud)\n\n原来的名字是,但是通过php的函数Trevi\xc3\xb1o修改的。htmlentities
我该怎么做才能让 php 和 xml 很好地发挥作用?
\n\n在 Mac 上使用 Chrome 19。
\n