Skip to main content
added 16 characters in body
Source Link
Marius
  • 198.5k
  • 55
  • 424
  • 833

You don't need to write the xml using the magento lib.
Just make it a simple string.

$collection = Mage::getModel('catalog/product')->getCollection(); $collection->addAttributeToSelect('*'); //add filters if needed. //$collection->addAttributeToFilter('status', 1); //for example.

$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('*');
//add filters if needed.
//$collection->addAttributeToFilter('status', 1); //for example.

$padd = '    '; //4 spaces for identation
$eol = "\n"; //end of line
$xml = '<?xml version="1.0"?>'.$eol;
$xml .= '<products>'.$eol;
foreach ($collection as $product) {
    $xml .= $padd.'<product>'.$eol;
    $xml .= str_repeat($padd, 2).'<name>'.$product->getName().'</name>'.$eol;
    $xml .= str_repeat($padd, 2).'<description><![CDATA['.$product->getName().']]></description>'.$eol;
    $xml .= str_repeat($padd, 2).'<price><![CDATA['.$product->getFinalPrice().']]></price>'.$eol;
    //add here all the attributes you need to export
    $xml .= $padd.'</product>'.$eol;
}
$xml .= '</products>'.$eol;
//Do something with $xml - save it in a file or echo it.

You don't need to write the xml using the magento lib.
Just make it a simple string.

$collection = Mage::getModel('catalog/product')->getCollection(); $collection->addAttributeToSelect('*'); //add filters if needed. //$collection->addAttributeToFilter('status', 1); //for example.

$padd = '    '; //4 spaces for identation
$eol = "\n"; //end of line
$xml = '<?xml version="1.0"?>'.$eol;
$xml .= '<products>'.$eol;
foreach ($collection as $product) {
    $xml .= $padd.'<product>'.$eol;
    $xml .= str_repeat($padd, 2).'<name>'.$product->getName().'</name>'.$eol;
    $xml .= str_repeat($padd, 2).'<description><![CDATA['.$product->getName().']]></description>'.$eol;
    $xml .= str_repeat($padd, 2).'<price><![CDATA['.$product->getFinalPrice().']]></price>'.$eol;
    //add here all the attributes you need to export
    $xml .= $padd.'</product>'.$eol;
}
$xml .= '</products>'.$eol;
//Do something with $xml - save it in a file or echo it.

You don't need to write the xml using the magento lib.
Just make it a simple string.

$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('*');
//add filters if needed.
//$collection->addAttributeToFilter('status', 1); //for example.

$padd = '    '; //4 spaces for identation
$eol = "\n"; //end of line
$xml = '<?xml version="1.0"?>'.$eol;
$xml .= '<products>'.$eol;
foreach ($collection as $product) {
    $xml .= $padd.'<product>'.$eol;
    $xml .= str_repeat($padd, 2).'<name>'.$product->getName().'</name>'.$eol;
    $xml .= str_repeat($padd, 2).'<description><![CDATA['.$product->getName().']]></description>'.$eol;
    $xml .= str_repeat($padd, 2).'<price><![CDATA['.$product->getFinalPrice().']]></price>'.$eol;
    //add here all the attributes you need to export
    $xml .= $padd.'</product>'.$eol;
}
$xml .= '</products>'.$eol;
//Do something with $xml - save it in a file or echo it.
Source Link
Marius
  • 198.5k
  • 55
  • 424
  • 833

You don't need to write the xml using the magento lib.
Just make it a simple string.

$collection = Mage::getModel('catalog/product')->getCollection(); $collection->addAttributeToSelect('*'); //add filters if needed. //$collection->addAttributeToFilter('status', 1); //for example.

$padd = '    '; //4 spaces for identation
$eol = "\n"; //end of line
$xml = '<?xml version="1.0"?>'.$eol;
$xml .= '<products>'.$eol;
foreach ($collection as $product) {
    $xml .= $padd.'<product>'.$eol;
    $xml .= str_repeat($padd, 2).'<name>'.$product->getName().'</name>'.$eol;
    $xml .= str_repeat($padd, 2).'<description><![CDATA['.$product->getName().']]></description>'.$eol;
    $xml .= str_repeat($padd, 2).'<price><![CDATA['.$product->getFinalPrice().']]></price>'.$eol;
    //add here all the attributes you need to export
    $xml .= $padd.'</product>'.$eol;
}
$xml .= '</products>'.$eol;
//Do something with $xml - save it in a file or echo it.