使用Php实现递归遍历,打印出所有的属性节点
<?php
//打印出所有的属性节点方法
function dumpNodes($node){
if($node == null) return;
if($node->hasAttributes()){
$length = $node->attributes->length;
for ($i = 0; $i < $length; ++$i) {
$name = $node->attributes->item($i)->name;
var_dump($node->attributes->item($i));
}
}
if($node->childNodes){
foreach ($node->childNodes as $child){
$this->dumpNodes($child);
}
}
}
?>
0 条评论