Home >Backend Development >PHP Tutorial >attributes() 出错

attributes() 出错

WBOY
WBOYOriginal
2016-06-20 12:40:291244browse

$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
可以在两个系统间转换

但你也得先转再用吧

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn