dongxi1320 2019-04-07 13:01
浏览 20

没有创建输出XML

I have a script that should create a XML output as a product feed for price compare service.. something like google merchants. There is a problem with a script that I can't find out. The script seems to be working but it doesn't create any XML output file.

Can you please tell me where is a problem? Thank you!

<?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();
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值