我正在解析xml并面临使用属性访问标签的一些问题。
我试图获取<link title="Object">
标签的href属性的值。到目前为止,我只获得了#MODS元数据&#34;。
如何使用simplexml访问我想要的内容?
$endpoint = "https://www.nb.no/services/search/v2/search?q=test&itemsPerPage=4";
$xml = simplexml_load_file($endpoint);
$xml->registerXPathNamespace('nb');
$nbibres = array();
foreach ($xml->entry as $article) {
$title = $article->title;
$mediatype = $article->children('nb', true)->mediatype;
$url = $article->link->attributes()->title;
var_dump($url);
}
示例条目:
<entry>
<id>
http://www.nb.no/services/search/v2/search/6a2a78edd1d4a359ccd07ac8310967ff
</id>
<title type="text">Test</title>
<summary type="text"/>
<link title="MODS metadata" rel="via" type="text/xml" href="http://www.nb.no/services/search/v2/mods/6a2a78edd1d4a359ccd07ac8310967ff"/>
<link title="Holdings" rel="related" type="text/xml" href="http://www.nb.no/services/search/v2/holdings/6a2a78edd1d4a359ccd07ac8310967ff"/>
<link title="Object" rel="related" type="text/html" href="http://urn.nb.no/URN:NBN:no-nb_digiebok_110"/>
<link title="Struct" rel="related" type="text/xml" href="http://www.nb.no/services/search/v2/struct/6a2a78edd1d4a359ccd07ac8310967ff"/>
<nb:digital xmlns:nb="http://www.nb.no/xml/search/1.0/">true</nb:digital>
<nb:mainentry xmlns:nb="http://www.nb.no/xml/search/1.0/">Econ Pöyry</nb:mainentry>
<nb:mediatype xmlns:nb="http://www.nb.no/xml/search/1.0/">Bøker</nb:mediatype>
<nb:languages xmlns:nb="http://www.nb.no/xml/search/1.0/">nob</nb:languages>
<nb:isbn xmlns:nb="http://www.nb.no/xml/search/1.0/">9788282321631</nb:isbn>
<nb:urn xmlns:nb="http://www.nb.no/xml/search/1.0/">URN:NBN:no-nb_digiebok_110</nb:urn>
<nb:sesamid xmlns:nb="http://www.nb.no/xml/search/1.0/">6a2a78edd1d4a359ccd07ac8310967ff</nb:sesamid>
<nb:namecreator xmlns:nb="http://www.nb.no/xml/search/1.0/">Econ Pöyry</nb:namecreator>
<nb:namecreators xmlns:nb="http://www.nb.no/xml/search/1.0/">Econ Pöyry</nb:namecreators>
<nb:year xmlns:nb="http://www.nb.no/xml/search/1.0/">2011</nb:year>
<nb:contentclasses xmlns:nb="http://www.nb.no/xml/search/1.0/">restricted</nb:contentclasses>
<nb:metadataclasses xmlns:nb="http://www.nb.no/xml/search/1.0/">public</nb:metadataclasses>
<nb:date xmlns:nb="http://www.nb.no/xml/search/1.0/">2011-01-01</nb:date>
</entry>