【发布时间】:2011-03-26 00:08:45
【问题描述】:
所以,我有这段代码在我的 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;
}
}
}
【问题讨论】: