Hey, I wondered if you might be able to check over my controller here. I’m using the library to create a google base feed, saving it as an xml file as follows:
My ‘feeds’ controller with the google function:
function google() {
$this->load->helper('file');
$this->load->model('products_model', '', TRUE);
/*Fetch products from database*/
$this->load->model('products_model');
$products_model = $this->products_model->getAllProducts();
// Load XML writer library
$this->load->library('MY_Xml_writer');
// Initiate class
$xml = new MY_Xml_writer;
$xml->setRootName('channel');
$xml->initiate();
/*Construct XML*/
foreach ($products_model as $product) {
$xml->startBranch('item');
$xml->addNode('title', $product->product_name);
$xml->addNode('link', $product->product_slug);
$xml->addNode('guid', $product->product_slug);
$xml->addNode('description', $product->product_desc);
$xml->addNode('g:image_link', $product->product_image1);
$xml->addNode('g:price', $product->product_price);
$xml->addNode('g:condition', 'new');
$xml->addNode('g:id', $product->product_id);
$xml->endBranch();
}
if ( ! write_file('./application/views/feeds/google.xml', $xml->getXml(true)))
{
echo 'Unable to write the file';
}
else
{
echo 'File written!';
}So when I hit http://mydomain.com/feeds/google I would like it to save out the xml at http://mydomain.com/feeds/google.xml
However, when I run this I get the following error:
This page contains the following errors:
error on line 1 at column 6: XML declaration allowed only at the start of the document
Below is a rendering of the page up to the first error.
When I open the google.xml file, it does contain the products. I would be very grateful if you might be able to help fix the error?
Thank you.