find value in nested tag in xml with php

We have used xpath to find out a tags value inside nested xml document. Example as :


// raw xml string
$string = <<<XML
                	<h1>sample text</h1>

// preparaing xml document
$xml = new SimpleXMLElement($string);

// Search for the text inside <html><body><div><div><span><h1>
// whole path with root is given here
$result = $xml->xpath('/html/body/div/div/span/h1');

while(list( , $node) = each($result)) {
    echo 'test found is : ' . $node;