Re: XPath query not working as expected
- From: yawnmoth <terra1024@xxxxxxxxx>
- Date: Sat, 24 Jan 2009 14:11:29 -0800 (PST)
On Jan 24, 11:15 am, Michael Fesser <neti...@xxxxxx> wrote:
$xml = new DOMDocument();
$xpath = new DOMXPath($xml);
//$result = $xpath->query('//descendant::font[@color=blue]');
//$result = $xpath->query('//font[@color=blue]');
$result = $xpath->query('//font');
echo "length = " . $result->length . '<br />';
for ($i = 0; $i < $result->length; $i++)
echo $result->item($i)->textContent . '<br />';
echo $result->item($i)->nodeValue . '<br />';
Why is the length being returned 0? Shouldn't it be 1?
Counting nodes starts with 1, so this query
should work as expected.
Nice catch. The problem with the other two, incidentally, (the two
that are commented out) is that I wasn't encapsulating the attribute
value in quotes, be they single or double .
- Prev by Date: Announcing PHPCamp.net
- Next by Date: Looking for a php/mysql (using google api's) programmer
- Previous by thread: Re: XPath query not working as expected
- Next by thread: Announcing PHPCamp.net