function createXmls($cars){
$xml = new DOMDocument();
$xml->formatOutput = TRUE;
$xml->encoding = 'utf8';
$root = $xml->createElement('urlset');
if (count($cars) > 0){
foreach($cars as $car){
if(count($car['child'])>0 ){
foreach($car['child'] as $child){
if($child['status'] ==1 && $child['is_show'] ==1){
$a = $xml->createElement('url');
$loc = $xml->createElement('loc');
$loc->appendChild($xml->createCDATASection('http://m.kmaiche.net/cars/detail/pid/'.$car['cate_id'].'/cityid/'.$car['city_id'].'/id/'.$child['cate_id']));
$a->appendChild($loc);
$data = $xml->createElement('data');
$name=$xml->createElement('name');
$name->appendChild($xml->createCDATASection($child['cate_name']));
$data->appendChild($name);
$outerID=$xml->createElement('outerID');
$outerID->appendChild($xml->createCDATASection($car['city_id'].$child['cate_id']));
$data->appendChild($outerID);
$sellerName=$xml->createElement('sellerName');
$sellerName->appendChild($xml->createCDATASection('快迈车'));
$data->appendChild($sellerName);
$logo=$xml->createElement('logo');
$logo->appendChild($xml->createCDATASection("http://img.km360.cn/images/lzweb/logo.png"));
$data->appendChild($logo);
$image=$xml->createElement('image');
$image->appendChild($xml->createCDATASection($child['img_url1']));
$data->appendChild($image);
$city=$xml->createElement('city');
$city->appendChild($xml->createCDATASection($car['city_name']));
$data->appendChild($city);
$price=$xml->createElement('price');
$price->appendChild($xml->createCDATASection(19.5));
$data->appendChild($price);
$priceUnit=$xml->createElement('priceUnit');
$priceUnit->appendChild($xml->createCDATASection(RMB));
$data->appendChild($priceUnit);
$brand=$xml->createElement('brand');
$brand->appendChild($xml->createCDATASection($car['brand_name']));
$data->appendChild($brand);
$brandUrl=$xml->createElement('brandUrl');
$brandUrl->appendChild($xml->createCDATASection('http://www.kmaiche.net/search/list/cate/'.$car['cate_id'].'/'));
$data->appendChild($brandUrl);
// $category=$xml->createElement('manufacturer');
// $category->appendChild($xml->createCDATASection($car['cate_name']));
// $data->appendChild($category);
// $categoryUrl=$xml->createElement('categoryUrl');
// $categoryUrl->appendChild($xml->createTextNode(''));
// $data->appendChild($categoryUrl);
$availability=$xml->createElement('availability');
$availability->appendChild($xml->createCDATASection(1));
$data->appendChild($availability);
$choice=$xml->createElement('choice');
$attribute=$xml->createElement('attribute');
$choice->appendChild($attribute);
$key=$xml->createElement('key');
$key->appendChild($xml->createCDATASection('pcLoc'));
$attribute->appendChild($key);
$value=$xml->createElement('value');
$value->appendChild($xml->createCDATASection('http://www.kmaiche.net/cars/detail/pid/'.$car['cate_id'].'/cityid/'.$car['city_id'].'/id/'.$child['cate_id']));
$attribute->appendChild($value);
$attribute14=$xml->createElement('attribute');
$key14=$xml->createElement('key');
$key14->appendChild($xml->createCDATASection('pcLocLead'));
$attribute14->appendChild($key14);
$value14=$xml->createElement('value');
$value14->appendChild($xml->createCDATASection('http://lz.leadscar.cn/cars/detail/pid/'.$car['cate_id'].'/cityid/'.$car['city_id'].'/id/'.$child['cate_id']));
$attribute14->appendChild($value14);
$choice->appendChild($attribute14);
$attribute16=$xml->createElement('attribute');
$key16=$xml->createElement('key');
$key16->appendChild($xml->createCDATASection('pcLeadbrandUrl'));
$attribute16->appendChild($key16);
$value16=$xml->createElement('value');
$value16->appendChild($xml->createCDATASection('http://lz.leadscar.cn/search/list/cate/'.$car['cate_id'].'/'));
$attribute16->appendChild($value16);
$choice->appendChild($attribute16);
$attribute17=$xml->createElement('attribute');
$key17=$xml->createElement('key');
$key17->appendChild($xml->createCDATASection('wapLeadbrandUrl'));
$attribute17->appendChild($key17);
$value17=$xml->createElement('value');
$value17->appendChild($xml->createCDATASection('http://m.leadscar.cn/search/list/cate/'.$car['cate_id'].'/'));
$attribute17->appendChild($value17);
$choice->appendChild($attribute17);
$attribute15=$xml->createElement('attribute');
$key15=$xml->createElement('key');
$key15->appendChild($xml->createCDATASection('wapLocLead'));
$attribute15->appendChild($key15);
$value15=$xml->createElement('value');
$value15->appendChild($xml->createCDATASection('http://m.leadscar.cn/cars/detail/pid/'.$car['cate_id'].'/cityid/'.$car['city_id'].'/id/'.$child['cate_id']));
$attribute15->appendChild($value15);
$choice->appendChild($attribute15);
$attribute13=$xml->createElement('attribute');
$key13=$xml->createElement('key');
$key13->appendChild($xml->createCDATASection('manufacturer'));
$attribute13->appendChild($key13);
$value13=$xml->createElement('value');
$value13->appendChild($xml->createCDATASection($car['cate_name']));
$attribute13->appendChild($value13);
$choice->appendChild($attribute13);
$attribute1=$xml->createElement('attribute');
$key1=$xml->createElement('key');
$key1->appendChild($xml->createCDATASection('type'));
$attribute1->appendChild($key1);
$value1=$xml->createElement('value');
$value1->appendChild($xml->createCDATASection($child['cate_name']));
$attribute1->appendChild($value1);
$choice->appendChild($attribute1);
$attribute2=$xml->createElement('attribute');
$key2=$xml->createElement('key');
$key2->appendChild($xml->createCDATASection('groupBuyingTime'));
$attribute2->appendChild($key2);
$value2=$xml->createElement('value');
$value2->appendChild($xml->createCDATASection($car['lz_tg_date']."(".$car['date'].")"));
$attribute2->appendChild($value2);
$choice->appendChild($attribute2);
$attribute3=$xml->createElement('attribute');
$key3=$xml->createElement('key');
$key3->appendChild($xml->createCDATASection('groupBuyingLocation'));
$attribute3->appendChild($key3);
$value3=$xml->createElement('value');
$value3->appendChild($xml->createCDATASection($car['tg_address']));
$attribute3->appendChild($value3);
$choice->appendChild($attribute3);
$attribute4=$xml->createElement('attribute');
$key4=$xml->createElement('key');
$key4->appendChild($xml->createCDATASection('groupBuyingPrice'));
$attribute4->appendChild($key4);
$value4=$xml->createElement('value');
$value4->appendChild($xml->createCDATASection(19.5));
$attribute4->appendChild($value4);
$choice->appendChild($attribute4);
$attribute12=$xml->createElement('attribute');
$key12=$xml->createElement('key');
$key12->appendChild($xml->createCDATASection('unit'));
$attribute12->appendChild($key12);
$value12=$xml->createElement('value');
$value12->appendChild($xml->createCDATASection('万元'));
$attribute12->appendChild($value12);
$choice->appendChild($attribute12);
$attribute5=$xml->createElement('attribute');
$key5=$xml->createElement('key');
$key5->appendChild($xml->createCDATASection('groupBuyingHotline'));
$attribute5->appendChild($key5);
$value5=$xml->createElement('value');
$value5->appendChild($xml->createCDATASection($car['telephone']));
$attribute5->appendChild($value5);
$choice->appendChild($attribute5);
$attribute6=$xml->createElement('attribute');
$key6=$xml->createElement('key');
$key6->appendChild($xml->createCDATASection('applicationNumber'));
$attribute6->appendChild($key6);
$value6=$xml->createElement('value');
$value6->appendChild($xml->createCDATASection($car['virtual_num']));
$attribute6->appendChild($value6);
$choice->appendChild($attribute6);
$attribute7=$xml->createElement('attribute');
$key7=$xml->createElement('key');
$key7->appendChild($xml->createCDATASection('CumulativeApplicationNumber'));
$attribute7->appendChild($key7);
$value7=$xml->createElement('value');
$value7->appendChild($xml->createCDATASection($car['virtual_num']));
$attribute7->appendChild($value7);
$choice->appendChild($attribute7);
$attribute8=$xml->createElement('attribute');
$key8=$xml->createElement('key');
$key8->appendChild($xml->createCDATASection('merit1'));
$attribute8->appendChild($key8);
$value8=$xml->createElement('value');
$value8->appendChild($xml->createCDATASection("低价保证"));
$attribute8->appendChild($value8);
$choice->appendChild($attribute8);
$attribute9=$xml->createElement('attribute');
$key9=$xml->createElement('key');
$key9->appendChild($xml->createCDATASection('merit2'));
$attribute9->appendChild($key9);
$value9=$xml->createElement('value');
$value9->appendChild($xml->createCDATASection("4S提车"));
$attribute9->appendChild($value9);
$choice->appendChild($attribute9);
$attribute10=$xml->createElement('attribute');
$key10=$xml->createElement('key');
$key10->appendChild($xml->createCDATASection('merit3'));
$attribute10->appendChild($key10);
$value10=$xml->createElement('value');
$value10->appendChild($xml->createCDATASection("完全免费"));
$attribute10->appendChild($value10);
$choice->appendChild($attribute10);
$attribute11=$xml->createElement('attribute');
$key11=$xml->createElement('key');
$key11->appendChild($xml->createCDATASection('merit4'));
$attribute11->appendChild($key11);
$value11=$xml->createElement('value');
$value11->appendChild($xml->createCDATASection("便捷服务"));
$attribute11->appendChild($value11);
$choice->appendChild($attribute11);
$data->appendChild($choice);
$a->appendChild($data);
$root->appendChild($a);
}
}
}
}
}
$xml->appendChild($root);
//print_r($xml);
// $path = "/b/web/kmproject/data/xml/cars.xml";
$path = APPLICATION_PATH.'/download/cars.xml';
//$path="./data/xml/cars.xml";
header('Content-Type: text/html;charset=UTF-8');
if ($xml->save($path) !== FALSE){
echo 'cars.xml已经生成保存!';
}else{
echo 'cars.xml生成失败';
}
}
$cars =
array(1) { | |
[0]=> | |
array(17) { | |
["id"]=> | |
string(4) "6513" | |
["cate_id"]=> | |
string(3) "575" | |
["lz_tg_date"]=> | |
string(10) "2018-06-02" | |
["city_id"]=> | |
string(3) "322" | |
["virtual_num"]=> | |
string(3) "152" | |
["tg_address"]=> | |
string(0) "" | |
["tg_highlights"]=> | |
string(0) "" | |
["status"]=> | |
string(1) "1" | |
["telephone"]=> | |
string(0) "" | |
["cate_name"]=> | |
string(12) "北汽威旺" | |
["img_url"]=> | |
string(33) "/static/uploads/1493272557534.png" | |
["pid"]=> | |
string(1) "7" | |
["city_name"]=> | |
string(6) "吴忠" | |
["img_url1"]=> | |
string(49) "http://imgbeta.km360.cn/uploads/1493272557534.png" | |
["date"]=> | |
string(9) "星期六" | |
["brand_name"]=> | |
string(12) "北汽威旺" | |
["child"]=> | |
array(8) { | |
[0]=> | |
array(6) { | |
["cate_name"]=> | |
string(15) "北汽威旺M20" | |
["img_url"]=> | |
string(33) "/static/uploads/1476087341452.jpg" | |
["cate_id"]=> | |
string(3) "576" | |
["status"]=> | |
string(1) "1" | |
["is_show"]=> | |
string(1) "1" | |
["img_url1"]=> | |
string(49) "http://imgbeta.km360.cn/uploads/1476087341452.jpg" | |
} | |
[1]=> | |
array(6) { | |
["cate_name"]=> | |
string(15) "北汽威旺306" | |
["img_url"]=> | |
string(33) "/static/uploads/1476170827652.jpg" | |
["cate_id"]=> | |
string(3) "718" | |
["status"]=> | |
string(1) "1" | |
["is_show"]=> | |
string(1) "1" | |
["img_url1"]=> | |
string(49) "http://imgbeta.km360.cn/uploads/1476170827652.jpg" | |
} | |
[2]=> | |
array(6) { | |
["cate_name"]=> | |
string(15) "北汽威旺307" | |
["img_url"]=> | |
string(33) "/static/uploads/1476170839680.jpg" | |
["cate_id"]=> | |
string(3) "719" | |
["status"]=> | |
string(1) "1" | |
["is_show"]=> | |
string(1) "1" | |
["img_url1"]=> | |
string(49) "http://imgbeta.km360.cn/uploads/1476170839680.jpg" | |
} | |
[3]=> | |
array(6) { | |
["cate_name"]=> | |
string(15) "北汽威旺007" | |
["img_url"]=> | |
string(33) "/static/uploads/1476170853942.jpg" | |
["cate_id"]=> | |
string(3) "720" | |
["status"]=> | |
string(1) "1" | |
["is_show"]=> | |
string(1) "1" | |
["img_url1"]=> | |
string(49) "http://imgbeta.km360.cn/uploads/1476170853942.jpg" | |
} | |
[4]=> | |
array(6) { | |
["cate_name"]=> | |
string(15) "北汽威旺M30" | |
["img_url"]=> | |
string(33) "/static/uploads/1476172665284.jpg" | |
["cate_id"]=> | |
string(3) "797" | |
["status"]=> | |
string(1) "1" | |
["is_show"]=> | |
string(1) "1" | |
["img_url1"]=> | |
string(49) "http://imgbeta.km360.cn/uploads/1476172665284.jpg" | |
} | |
[5]=> | |
array(6) { | |
["cate_name"]=> | |
string(15) "北汽威旺S50" | |
["img_url"]=> | |
string(33) "/static/uploads/1476174827804.jpg" | |
["cate_id"]=> | |
string(3) "960" | |
["status"]=> | |
string(1) "1" | |
["is_show"]=> | |
string(1) "1" | |
["img_url1"]=> | |
string(49) "http://imgbeta.km360.cn/uploads/1476174827804.jpg" | |
} | |
[6]=> | |
array(6) { | |
["cate_name"]=> | |
string(15) "北汽威旺M35" | |
["img_url"]=> | |
string(33) "/static/uploads/1476174839770.jpg" | |
["cate_id"]=> | |
string(3) "961" | |
["status"]=> | |
string(1) "1" | |
["is_show"]=> | |
string(1) "1" | |
["img_url1"]=> | |
string(49) "http://imgbeta.km360.cn/uploads/1476174839770.jpg" | |
} | |
[7]=> | |
array(6) { | |
["cate_name"]=> | |
string(16) "北汽威旺M50f" | |
["img_url"]=> | |
string(33) "/static/uploads/1484794731834.jpg" | |
["cate_id"]=> | |
string(4) "1187" | |
["status"]=> | |
string(1) "1" | |
["is_show"]=> | |
string(1) "1" | |
["img_url1"]=> | |
string(49) "http://imgbeta.km360.cn/uploads/1484794731834.jpg" | |
} | |
} | |
} | |
} |