The declaration in the second line of your XML gives two XML namespaces:
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:zapi="http://zotero.org/ns/api">
The first xmlns
attribute, with no colon-separated suffix, sets the "default" namespace for the entry
element as being http://www.w3.org/2005/Atom
, and descendant nodes with no prefix are in that namespace by default. To be able to access these elements with a "default" namespace using XPath, you need to set a namespace using registerXPathNamespace
, and then perform your query, prefixing the element you're looking for (link
) with the namespace:
$xml->registerXPathNamespace('d', 'http://www.w3.org/2005/Atom');
$php_up = $xml->xpath("//d:link[@rel='up']");
var_dump($php_up);
Output:
array(1) {
[0] =>
class SimpleXMLElement#2 (1) {
public $@attributes =>
array(3) {
'rel' =>
string(2) "up"
'type' =>
string(20) "application/atom+xml"
'href' =>
string(9) "some link"
}
}
}