无法弄清楚如何确定 SimpleXML 节点是否为空
所以我有这样的代码:
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
中。代码> 或不。
So I have this code:
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>");
}
}
Basically, I'm trying to save IDs to an XML file if the Passage
node exists, but it seems to be storing every ID whether nodes exist within Passage
or not.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用
empty()
会发生什么What happens if you use
empty()
您可以将值转换为字符串并与空字符串进行比较(有点像 如何检查 simplexml 对象的值):
You can cast the value as a string and compare to an empty string (sort of like how to check a value of simplexml object):