How to Create an XML Data Feed from Your Car Dealership’s Website

This article describes a process for generating an XML feed from vehicle data extracted directly from VDPs on a dealer’s website. Of course, the process is not limited to car dealer websites. It can be applied to any type of website.

In order to create an XML data feed, you first need to extract the data from your VDPs.

After you’ve extracted the data, you’ll now have a JSON object from which to create your XML feed. To convert the JSON to XML, I’m going to use PHP.

// Decode and sanitize the the Kimono API URL
$url = filter_var(urldecode($_REQUEST['url']),FILTER_SANITIZE_URL);

// If you named the collection in your API something other than collection1 (the default), include the collection parameter in your URL
// e.g. &collection=vdp_data
if(isset($_REQUEST['collection']) && !empty($_REQUEST['collection'])) {
	$collection = filter_var($_REQUEST['collection'],FILTER_SANITIZE_STRING);
} else {
	$collection = 'collection1';

// Check that the value of 'url' is a kimono API URL
if(preg_match("~https://www\.kimonolabs\.com/api/[a-z0-9]+\?apikey=[a-zA-Z0-9]+~", $url)) {
	// Function definition to convert array to xml (adapted from
	function array_to_xml($array, &$xml) {
		foreach($array as $key => $value) {
			if(is_array($value)) {
					$subnode = $xml->addChild("$key");
					array_to_xml($value, $subnode);
				} else {
					$subnode = $xml->addChild("item");
					array_to_xml($value, $subnode);
			} else {
	// Initialize session and set URL for cURL.
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
	// Set so curl_exec returns the result instead of outputting it.
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	// Get the response and close the channel.
	$response = curl_exec($ch);
	// Convert the response to an array
	$response = json_decode($response, true);
	// Grab just the "collection"
	$response = $response['results'][$collection];
	// creating object of SimpleXMLElement
	$xml = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"UTF-8\"?><inventory></inventory>");
	array_to_xml($response, $xml);
	header('content-type: text/xml');
	header("Cache-Control: no-store, no-cache, must-revalidate");
	header("Cache-Control: post-check=0, pre-check=0", false);
	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
	$dom = new DOMDocument("1.0");
	$dom->preserveWhiteSpace = false;
	$dom->formatOutput = true;
	echo $dom->saveXML();

} else {
	echo "Oops. Something went wrong.";

So, let’s say you save this script as a file named feed-generator.php.

There are two parameters you can pass to the script.

  • url
    • required
    • the url encoded url of your kimono API
    • e.g. feed-generator.php?
  • collection
    • optional
    • whatever you named your “collection” when creating your API (not the name of the API, but the collection within the API)
    • e.g. &collection=vdp_data

So, you might end up with a feed URL like:

Lo and behold, you’ve got yourself a XML feed of your VDPs (or whatever data you collected with your Kimono API).

Related Posts

3 Responses
  1. Hello,
    The Kimono Labs Chrome Extension, no longer exists -it seems to now be a part of Heroku.
    Is there an alternative to fit in with your “create an XML feed from VDPs” guide?

  2. You could use to achieve effectively the same result. Give that a try and let me know how it goes. I’ll update the post as soon as I get the chance.

  3. I am thankful to this blog giving unique and helpful knowledge about this topic.

Leave a Reply