<?php
require_once('classes/db2xml/db2xml.class.inc');
// Base XML file
$XML_skelFile = 'xml/store_skel.xml';
// Database
$dbHostname = 'localhost';
$dbUser = 'db2xml';
$dbPassword = 'db2xml';
$dbName = 'db2xml';
try {
$db2xml = new db2xml($XML_skelFile, $dbHostname, $dbUser, $dbPassword, $dbName);
// get data from Database and save it to a save point
$db2xml->setDataFromDB('book', 'SELECT * FROM book WHERE idStore=1');
$db2xml->setDataFromDB('cd', 'SELECT * FROM cd WHERE idStore=1');
$db2xml->setDataFromDB('dvd', 'SELECT * FROM dvd WHERE idStore=1');
$db2xml->setDataFromDB('game', 'SELECT * FROM game WHERE idStore=1');
$db2xml->setDataFromDB('mp3tracks', 'SELECT * FROM mp3tracks WHERE idStore=1');
$db2xml->setDataFromDB('ownproduct', 'SELECT * FROM ownproduct WHERE idStore=1');
$db2xml->setDataFromDB('store', 'SELECT * FROM store WHERE idStore=1');
// build the <infos/> child data
$db2xml->newChild(array('name'=>'infos'));
$data = $db2xml->getDBData('store');
$tmp = array();
$tmp[] = array('name'=>'storeid', 'value'=>$data['idStore'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:decimal'));
$tmp[] = array('name'=>'title', 'value'=>$data['Title'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'banner', 'value'=>$data['banner'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'image', 'value'=>$data['image'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'comment', 'value'=>$data['Description'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
foreach ($tmp as $element) $db2xml->newChild($element, '/response/infos');
// build the <links/> child data
$db2xml->newChild(array('name'=>'links'));
// we have 3 links
for ($i=0; $i<3; $i++) {
$db2xml->newChild(array('name'=>'link'), '/response/links');
}
// get inside each <link/> and insert link details
for ($i=0; $i<3; $i++) {
$tmp = array();
$tmp[] = array('name'=>'text', 'value'=>$data['Link_'.($i+1).'_Text'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'url', 'value'=>$data['Link_'.($i+1).'_Adresse'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
foreach ($tmp as $element) $db2xml->newChild($element, '/response/links/link['.($i+1).']');
}
// build the <products/>
$db2xml->newChild(array('name'=>'products'));
// build the /products/bakertaylor
$db2xml->newChild(array('name'=>'bakertaylor'), '/response/products');
$bakertaylor = 0;
// books
$data = $db2xml->getDBData('book');
for ($i = 0; $i < count($data); $i++) {
$tmp = array();
$tmp[] = array('name'=>'itemid', 'value'=>$data[$i]['itemid'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:decimal'));
$tmp[] = array('name'=>'itemtype', 'value'=>$data[$i]['itemtype'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'userprice', 'value'=>$data[$i]['userprice'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:float'));
$tmp[] = array('name'=>'usercomment', 'value'=>$data[$i]['usercomment'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'author', 'value'=>$data[$i]['author'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'title', 'value'=>$data[$i]['title'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'instock', 'value'=>$data[$i]['instock'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'subject', 'value'=>$data[$i]['subject'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'image', 'value'=>$data[$i]['image'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'thumbnail', 'value'=>$data[$i]['thumbnail'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$db2xml->newChild(array('name'=>'product'), '/response/products/bakertaylor');
$bakertaylor++;
foreach ($tmp as $element) $db2xml->newChild($element, '/response/products/bakertaylor/product['.($bakertaylor).']');
}
// cds
$data = $db2xml->getDBData('cd');
for ($i = 0; $i < count($data); $i++) {
$tmp = array();
$tmp[] = array('name'=>'itemid', 'value'=>$data[$i]['itemid'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:decimal'));
$tmp[] = array('name'=>'itemtype', 'value'=>$data[$i]['itemtype'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'artist', 'value'=>$data[$i]['artist'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'userprice', 'value'=>$data[$i]['userprice'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:float'));
$tmp[] = array('name'=>'usercomment', 'value'=>$data[$i]['usercomment'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'instock', 'value'=>$data[$i]['instock'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'title', 'value'=>$data[$i]['title'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'genre', 'value'=>$data[$i]['genre'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'image', 'value'=>$data[$i]['image'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'thumbnail', 'value'=>$data[$i]['thumbnail'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$db2xml->newChild(array('name'=>'product'), '/response/products/bakertaylor');
$bakertaylor++;
foreach ($tmp as $element) $db2xml->newChild($element, '/response/products/bakertaylor/product['.($bakertaylor).']');
}
// dvds
$data = $db2xml->getDBData('dvd');
for ($i = 0; $i < count($data); $i++) {
$tmp = array();
$tmp[] = array('name'=>'itemid', 'value'=>$data[$i]['itemid'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:decimal'));
$tmp[] = array('name'=>'itemtype', 'value'=>$data[$i]['itemtype'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'actor', 'value'=>$data[$i]['actor'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'userprice', 'value'=>$data[$i]['userprice'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:float'));
$tmp[] = array('name'=>'usercomment', 'value'=>$data[$i]['usercomment'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'instock', 'value'=>$data[$i]['instock'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'title', 'value'=>$data[$i]['title'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'genre', 'value'=>$data[$i]['genre'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'image', 'value'=>$data[$i]['image'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'thumbnail', 'value'=>$data[$i]['thumbnail'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$db2xml->newChild(array('name'=>'product'), '/response/products/bakertaylor');
$bakertaylor++;
foreach ($tmp as $element) $db2xml->newChild($element, '/response/products/bakertaylor/product['.($bakertaylor).']');
}
// games
$data = $db2xml->getDBData('game');
for ($i = 0; $i < count($data); $i++) {
$tmp = array();
$tmp[] = array('name'=>'itemid', 'value'=>$data[$i]['itemid'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:decimal'));
$tmp[] = array('name'=>'itemtype', 'value'=>$data[$i]['itemtype'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'manufacturer', 'value'=>$data[$i]['manufacturer'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'userprice', 'value'=>$data[$i]['userprice'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:float'));
$tmp[] = array('name'=>'usercomment', 'value'=>$data[$i]['usercomment'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'instock', 'value'=>$data[$i]['instock'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'title', 'value'=>$data[$i]['title'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'type', 'value'=>$data[$i]['type'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'typecode', 'value'=>$data[$i]['typecode'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'genre', 'value'=>$data[$i]['genre'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'image', 'value'=>$data[$i]['image'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'thumbnail', 'value'=>$data[$i]['thumbnail'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$db2xml->newChild(array('name'=>'product'), '/response/products/bakertaylor');
$bakertaylor++;
foreach ($tmp as $element) $db2xml->newChild($element, '/response/products/bakertaylor/product['.($bakertaylor).']');
}
// build the /products/sellown
$db2xml->newChild(array('name'=>'sellown'), '/response/products');
$sellown = 0;
$data = $db2xml->getDBData('ownproduct');
for ($i = 0; $i < count($data); $i++) {
$tmp = array();
$tmp[] = array('name'=>'itemid', 'value'=>$data[$i]['itemid'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:decimal'));
$tmp[] = array('name'=>'itemtype', 'value'=>$data[$i]['itemtype'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'title', 'value'=>$data[$i]['title'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'category', 'value'=>$data[$i]['category'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'sellername', 'value'=>$data[$i]['sellername'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'thumbnail', 'value'=>$data[$i]['thumbnail'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'Condition', 'value'=>$data[$i]['Condition'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'type', 'value'=>$data[$i]['type'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'typecode', 'value'=>$data[$i]['typecode'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'genre', 'value'=>$data[$i]['genre'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'image', 'value'=>$data[$i]['image'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'thumbnail', 'value'=>$data[$i]['thumbnail'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$db2xml->newChild(array('name'=>'product'), '/response/products/sellown');
$sellown++;
foreach ($tmp as $element) $db2xml->newChild($element, '/response/products/sellown/product['.($sellown).']');
}
// mp3
$db2xml->newChild(array('name'=>'mp3'), '/response/products');
$mp3 = 0;
$data = $db2xml->getDBData('mp3tracks');
for ($i = 0; $i < count($data); $i++) {
$tmp = array();
$tmp[] = array('name'=>'itemid', 'value'=>$data[$i]['itemid'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:decimal'));
$tmp[] = array('name'=>'itemtype', 'value'=>$data[$i]['itemtype'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'manufacturer', 'value'=>$data[$i]['manufacturer'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'userprice', 'value'=>$data[$i]['userprice'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:float'));
$tmp[] = array('name'=>'usercomment', 'value'=>$data[$i]['usercomment'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'instock', 'value'=>$data[$i]['instock'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'title', 'value'=>$data[$i]['title'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'type', 'value'=>$data[$i]['type'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'typecode', 'value'=>$data[$i]['typecode'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'genre', 'value'=>$data[$i]['genre'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'image', 'value'=>$data[$i]['image'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$tmp[] = array('name'=>'thumbnail', 'value'=>$data[$i]['thumbnail'], 'attribute'=>array('name'=>'type', 'value'=>'xsd:string'));
$db2xml->newChild(array('name'=>'product'), '/response/products/mp3');
$mp3++;
foreach ($tmp as $element) $db2xml->newChild($element, '/response/products/mp3/product['.($mp3).']');
}
echo $db2xml->getXML();
}
catch (Exception $e) {
echo $e->getMessage();
}
?> |