function cw_gb_write_xml($file, $data) { /* * Perform XML content */ $xml = <<<XML <?xml version="1.0" ?> <rss version="2.0" xmlns:g="http://base.google.com/ns/1.0" xmlns:c="http://base.google.com/cns/1.0"> <channel> <title>Products Catalog</title> <link>{$http_location}/{$_filename}</link> <description>Google Product Search feed for {$http_location}</description> XML; fwrite($file, $xml); // Header foreach ($data as $p) { $item = cw_hash2xml($p, 1); $xml = "<item>\n{$item}\n</item>\n"; fwrite($file, $xml); // Item } $xml = '</channel>' . "\n" . '</rss>'; // $xml = cw_xml_format($xml); fwrite($file, $xml); // Footer }
function cw_hash2xml($hash, $level = 0) { if (!is_array($hash)) { return cw_xml_escape($hash); } elseif (empty($hash)) { return ""; } $xmk = ""; foreach ($hash as $k => $v) { $xml .= str_repeat("\t", $level) . "<{$k}>" . cw_hash2xml($v, $level + 1) . "</{$k}>\n"; } if ($level > 0) { $xml = "\n" . $xml . "\n" . str_repeat("\t", $level); } return $xml; }