I'm new to xpath and am running into troubles with PHP's ancient XPath implementation. Is it correct, that //@url
is just the abbreviated form of //attribute::url
? I'm trying to query the flickr rss for testing, but the abbreviated query finds the correct nodes, whereas the verbose one returns 0 elements:
$xml = file_get_contents('http://api.flickr.com/services/feeds/geo/?format=rss_200');
$doc = new DOMDocument();
$doc->loadXML($xml);
$xpath = new DOMXPath($doc);
$xpath->query('//media:content/@url')->length > 0;
$xpath->query('//media:content/attribute::url')->length == 0;
Did I misunderstand the w3c specs or is this a PHP bug?
Related question:
The successful query returns DOMAttr
objects as expected. But is there no way to get the text value of these nodes directly? Something like //media:content/attribute::url/child::text()
? I would need that for a tool where the xpath queries will be entered by users and the error detection would be much better if I could expect DOMText objects (instead of coding for a multitude of DOM* objects).