Re: XPath query not working as expected
- From: Michael Fesser <netizen@xxxxxx>
- Date: Sat, 24 Jan 2009 18:15:11 +0100
..oO(yawnmoth)
<?php
$xml = new DOMDocument();
$xml->loadHTML('<html><body><font color="blue"><b>test</b></font></
body></html>');
$xpath = new DOMXPath($xml);
//$result = $xpath->query('//descendant::font[@color=blue]');
//$result = $xpath->query('//font[@color=blue]');
$result = $xpath->query('//font[0]');
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
//font[1]
should work as expected.
Micha
.
- Follow-Ups:
- Re: XPath query not working as expected
- From: yawnmoth
- Re: XPath query not working as expected
- References:
- XPath query not working as expected
- From: yawnmoth
- XPath query not working as expected
- Prev by Date: XPath query not working as expected
- Next by Date: Announcing PHPCamp.net
- Previous by thread: XPath query not working as expected
- Next by thread: Re: XPath query not working as expected
- Index(es):
Relevant Pages
|