続きその5
パーサー部分。
DOM XMLを使用したパーサー
<?php require_once 'HTTP/Request.php'; // del.icio.usのIDとパスワードを指定 $user = 'bobchin'; $pass = 'xxxxxxx'; $request = new HTTP_Request('https://api.del.icio.us/v1/posts/recent'); $request->setBasicAuth($user, $pass); $response = $request->sendRequest(); if (PEAR::isError($response)) { echo $response->getMessage(); exit; } $xml = $request->getResponseBody(); $dom = domxml_open_mem($xml); $entries = $dom->get_elements_by_tagname('post'); foreach ($entries as $entry) { $description = $href = null; foreach ($entry->attributes() as $attr) { if (in_array($attr->name, array('description', 'href'))) { ${$attr->name} = $attr->value; } if (!is_null($description) && !is_null($href)) { echo sprintf('%s: %s'.PHP_EOL, $description, $href); break; } } } ?>