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 :

<?php

// raw xml string
$string = <<<XML
<html>
    <body>
        <div>
            <div>
                <span>
                	<h1>sample text</h1>
				</span>
            </div>
        </div>
    </body>
</html>
XML;

// 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;
}
?>