【发布时间】:2019-04-11 07:37:00
【问题描述】:
我有一个带有节点和属性的 xml 文件
<hotspot name="hs1"/>
<hotspot name="hs2"/>
<hotspot name="hs3"/>
我想检查 nodc 热点是否存在以及是否存在特定的属性值。 我正在尝试这个,但 id 不起作用...
<?php
$file = 'hotspots.xml';
$xml = simplexml_load_file($file);
$var = $xml->xpath("//hotspot[@name='hs2']");
if (isset($var)) { echo 'does exist' } else {echo 'does not exist'}
?>
好吧,它根本不起作用(错误 500) 很抱歉成为这样的新手,非常感谢您的帮助!谢谢 !
【问题讨论】:
-
这不是 XML 文件。另请参阅此问题的答案:stackoverflow.com/q/845021/1255289
-
它是我的 xml 文件的一部分 ;)
-
@jeromebg 我的回答对你有用吗?
标签: php xpath attributes nodes simplexml