'; } ?>

Google Base API Sample

loadXML($xml); $xpath = new domxpath($dom); $nodes = $xpath->query('//entry'); echo '
    '; foreach ($nodes as $node) { echo '
  1. '; echo getSubNodeData($xpath, $node, 'title') . '
    '; echo 'Published: ' . getSubNodeData($xpath, $node, 'published') . '
    '; $itemUrl = ''; $subNodes = $xpath->query('link[@rel="alternate"][1]', $node); $itemUrl = $subNodes->item(0)->getAttribute('href'); echo '' . misc_toXml( niceUrl($itemUrl) ) . '
    '; echo '

  2. '; } echo '
'; } function niceUrl($url) { $maxLen = 70; $url = str_replace('http://', '', $url); if ( strlen($url) > $maxLen ) { $url = substr($url, 0, $maxLen) . '...'; } return $url; } function getSubNodeData($xpath, $node, $name) { $s = ''; $nodes = $xpath->query('.//' . $name . '[1]', $node); foreach ($nodes as $node) { $s = $node->firstChild->data; break; } return $s; } function misc_toXml($s) { $s = str_replace('&', '&', $s); $s = str_replace('<', '<', $s); $s = str_replace('>', '>', $s); return $s; } function misc_toAttribute($s) { $s = misc_toXml($s); $s = str_replace('"', '"', $s); return $s; } function getFileText_external($filePath) { $filetext = ''; if ( strpos($filePath, '://') !== false ) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $filePath); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $filetext = curl_exec($ch); curl_close($ch); } return $filetext; } ?>