tags:

views:

49

answers:

2
<key><name>testing name</name><result>success</result></key>

My PHP code:

$doc = new DOMDocument();
$doc->load( 'key.xml' );
$result = $doc->getElementsByTagName( "result" );
echo $result->item(0)->nodeValue;

I just need to extract the text value of "result", but it doesn't output that to me. Could you help me please?

A: 

i think you are using a regular variable as an object here. instead of

echo $result->item(0)->nodeValue;

why not use

echo $doc->item(0)->nodeValue;

since $doc is the instantiated object?

nickadeemus2002
Please familiarize yourself with [DOM API](http://ua2.php.net/manual/en/book.dom.php). `getElementsByTagName` returns a `DOMNodeList` object, which - in contrast to `DOMDocument` - does have an `item()` method. Your answer is completely wrong.
Gordon
Oh, but welcome to StackOverflow :)
Gordon
+3  A: 
Gordon