views:

673

answers:

3

Hello

when I want to test php array I use the following code

    print_r($myarray);

but know I want to see the data of an object my object is

    $xpath = new DOMXPath($doc);
    $myobject = $xpath->query('//*[ancestor-or-self::a]');

when I use

    print_r($myobject);

I get that output

    DOMNodeList Object ( )

I want to iterate through the values of this object to test the result of my query?

Thanks

+2  A: 

var_dump($myobject); may be what you're looking for

Ryan
Thanks but when I use var_dump I get this output "object(DOMNodeList)#9 (0) { }", I am sure this is not the output I am looking for because myobject has lots of data.
ahmed
apparently it does not. You may want to take a look at zombat's comment about xpath as that's territory i am not too well acquainted with DomXPath, but if var_dump says its empty then I'm quite certain it doesn't have what you think it has in it =(
Ryan
+1  A: 

Your xpath query is not matching anything in your XML.

From the DomXPath::query manual page:

Returns a DOMNodeList containing all nodes matching the given XPath expression . Any expression which do not return nodes will return an empty DOMNodeList.

zombat
Thanks but I am sure there is a data in my object I can print_some of the data when I use the following loop"foreach($xpath->query('//*[ancestor-or-self::a]') as $myobject) { echo $myobject->tagName;}"
ahmed
A: 

How about a recursive function?

Function XMLPrint_r($d_DomNode) {
    print $d_DomNode->$nodeName." ".$d_DomNode->$nodeValue."<br>";
    Foreach($d_DomNode->$childNodes as $d_ChildNode) {
        print " ";
        XMLPrint_r($d_ChildNode);
    }
}

I did not test this, but you get the idea.

Scott Lundberg