getElementsByTagName("am")->item(0); foreach($a->attributes() as">
当前位置:Gxlcms > PHP教程 > attributes()出错

attributes()出错

时间:2021-07-01 10:21:17 帮助过:19人阅读

$oa=new DOMDocument();$oa->load("o.xml");
$a=$oa->getElementsByTagName("am")->item(0);
foreach($a->attributes() as $x=>$y) {
echo $x; echo $y;
}
我想要读取xml指定节点的所有属性名和值,
为什么会出错
Fatal error: Call to undefined method DOMElement::attributes()


回复讨论(解决方案)

DOMElement ::getAttribute
SimpleXMLElement::attributes
两个不同的系统,不要弄混了

虽然有:
dom_import_simplexml
simplexml_import_dom
可以在两个系统间转换

但你也得先转再用吧

人气教程排行