Thursday, April 12, 2012

How to echo a DOMNodeList Object and a DOMElement Object?

I am using a loop to populate an array called $list. it is working like a charm..



// $content is a DOMNodeList Object  
// $value is a DOMElement Object

$list = array();

foreach ($content as $value){

array_push($list, 'title'=>$value->nodeValue);

}


Eventhough my loop is populating my array correctly, I would like to digg into that DOM thing a little more to understand things better (this DOM thing is to new to me...). So what I would like, is to see how the DOMNodeList Object ($content) and DOMElement Object ($value) looks like.



So my question is simple: how can I "echo-out" those 'elements'?





1 comment:

  1. Better than "echo-out" DomElement, read the documentation: http://php.net/manual/en/class.domelement.php.

    If you want to see XML representation, use http://www.php.net/manual/en/domnode.c14n.php, i.e.

    echo $value->c14N(false,true);

    ReplyDelete