如何将更改后的SimpleXML对象保存回文件?
因此,我有这个代码,它在我的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;
}
}
}