首页 > 解决方案 > 未创建输出 XML

问题描述

我有一个脚本,它应该创建一个 XML 输出作为价格比较服务的产品提要......类似于谷歌商家。脚本有问题,我找不到。该脚本似乎正在运行,但它没有创建任何 XML 输出文件。

你能告诉我哪里有问题吗?谢谢!

<?php
include_once('../api.php');

header('Content-Type:text/xml');
$xml = new DOMDocument('1.0', 'utf-8');
$root = $xml->createElement('SHOP');
$xml->appendChild($root);

foreach(productDetail(null, 'allinstock', null, null, null, null, null, null) as $key => $val) {
echo $val['item_id']."***<br />";
foreach(category(array('limit' => 1, 'id' => $val['cat1'])) as $keys => $vals) {

    if(!empty($val['cat2'])) {
        foreach(category(array('limit' => 1, 'id' => $val['cat2'])) as $keyse => $valse) {

            $catname = $vals['name'].' | '.$valse['name'];
        }
    } else {
        $catname = $vals['name'];
    }
}

if(empty($val['description'])) {

    $description = $val['product_name'];

} else {
    $description = $val['description'];
}



$info = $xml->createElement('SHOPITEM');
$root->appendChild($info);

$info_1 = $xml->createElement('ITEM_ID', $val['item_id']);
$info->appendChild($info_1);

$info_2 = $xml->createElement('PRODUCTNAME', $val['product_name']);
$info->appendChild($info_2);

$info_3 = $xml->createElement('PRODUCT', $val['product']);
$info->appendChild($info_3);

$info_4 = $xml->createElement('DESCRIPTION', $description);
$info->appendChild($info_4);

$info_5 = $xml->createElement('URL', $localUrl.'/'.$val['product_url']);
$info->appendChild($info_5);

$info_6 = $xml->createElement('IMGURL', $localUrl.'/img/produkt/'.$val['img_url']);
$info->appendChild($info_6);

/*$info_7 = $xml->createElement('IMGURL_ALTERNATIVE', $val['item_id']);
$info->appendChild($info_7);*/

$info_8 = $xml->createElement('PRICE_VAT', $val['price_vat']);
$info->appendChild($info_8);

$info_9 = $xml->createElement('MANUFACTURER', htmlspecialchars($val['manufacturer']));
$info->appendChild($info_9);

$info_10 = $xml->createElement('CATEGORYTEXT', $catname);
$info->appendChild($info_10);

$info_11 = $xml->createElement('DELIVERY_DATE', 0);
$info->appendChild($info_11);

/*$info_12 = $xml->createElement('DELIVERY');
$info->appendChild($info_12);

$info_13 = $xml->createElement('DELIVERY_ID', 'blablal');
$info_12->appendChild($info_13);

$info_14 = $xml->createElement('DELIVERY_PRICE', 'blablal');
$info_12->appendChild($info_14);

$info_15 = $xml->createElement('DELIVERY_PRICE_COD', 'blablal');
$info_12->appendChild($info_15);*/

}

echo $xml->saveXML();
?>

标签: phpxmlfeed

解决方案


推荐阅读