Page 1 of 1

PHP5 - Reading XML nodeValue reads object id#'s

Posted: Mon Feb 05, 2007 11:38 am
by mavedog21
Hey All,

This may be simple. I'd like to get my output to read the nodeValue of my requested tag ('name').
Why am I getting an object id# and how can I get it to print what the nodeValue of my node is.

example xml file:

Code: Select all

<neighborhood>
    <House>
        <name> Toms Jones </name>
    </House>
    <House>
          <name> Jennifer Reed </name>
    </House>
</neighborhood>
I looked and even copied the DOM getElementsByTagName function
http://us3.php.net/manual/en/function.d ... agname.php
and their response is readable. The difference is I want to read the value of the node and they
are reading the attribute of the node.


Code: Select all

<?php
 
$dom = new DomDocument;
$dom->preserveWhiteSpace = FALSE;
$dom->load('thexml.xml');
$params = $dom->getElementsByTagName('House');
 
foreach ($params as $param) {
       echo $param->getElementsByTagName('name').'<br />';

/* also tried
     echo $param->getElementsByTagName('name')->nodeValue.'<br />';
     echo $param->getElementsByTagName('name')->nodeName.'<br />';
*/
 
}
?>
prints:

Code: Select all

Object id #5
Object id #3

expected:

Code: Select all

Tom Jones
Jennifer Reed

Lastly is there a place to look for object id# references? So I know what the object id # is trying to tell me?
ie... Object ID#1 is a string value or something like that? Just curious.

thanks,

sky

Posted: Mon Feb 05, 2007 11:56 am
by feyd
The documentation page linked specifically says the method returns a DOMNodeList object.

http://php.net/ref.dom#dom.class.domnodelist

Posted: Mon Feb 05, 2007 12:23 pm
by Ollie Saunders
You might be looking for getElementByTagName('name')->firstChild->nodeValue