所以我知道我将尝试删除的节点的确切路径。我正在遍历几个 xml 文件以更新一些内容。为了添加一些新的内容,我必须先删除已经存在的内容。
这是我尝试使用的代码,但我收到 Parse 错误:语法错误,意外 T_UNSET
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) {
if (unset($xml->PrintQuestion->content->multichoice->feedback->hint->Passage)) {
$xml->PrintQuestion->content->multichoice->feedback->hint->addChild('Passage', $value[0]);
} else {
$xml->PrintQuestion->content->multichoice->feedback->hint->addChild('Passage', $value[0]);
}
}
}