foreach ($xml->PrintQuestion as $PrintQuestion) {
//if hint doesn't exist, store question id
if (!$PrintQuestion->content->multichoice->Feedback->hint->Passage) {
fwrite($fp, "<contentid filename=\"$value\">" . $PrintQuestion->attributes()->id . "</contentid>");
}
}
基本上,如果Passage节点存在,我正在尝试将ID保存到XML文件,但它似乎存储了每个ID,无论节点是否存在于Passage中.
解决方法:
如果你使用empty()会发生什么
if( empty($PrintQuestion->content->multichoice->Feedback->hint->Passage) ) {
fwrite($fp, "<contentid filename=\"$value\">" . $PrintQuestion->attributes()->id . "</contentid>");
}