🔥 Just Launched! Werra Premium Template for HyväSee it in Action

How to Export Magento Products in XML File

By Sanjay JethvaUpdated on May 22, 2025 2 min read

XML surely offers advantages over CSV that makes it more preferable for information exchange. Owing to its flexibility, object-oriented characteristic, protection against invalid data insertion, hierarchical nature and support for Unicode implicitly; it is the first choice to export data in Magento.

Magento Export is a useful feature required to create data feeds, send data to multiple people, backup product data, implement changes or import data to other websites. The default Magento only allows CSV or MS Excel file to export product data. To overcome the limitation and to be able to use XML file format, one needs to implement custom code given here!

Implement the below method to export Magento products in XML file. Make the migration of your store flawless by using XML file format for the import-export of the data.

Method to Export Magento Products in XML File:

<?php
require 'app/Mage.php';
Mage::app();
$storename = 'default';
$file = "products-top10.xml";
if (file_exists($file)) {
    unlink($file);
}
try {
    $products = Mage::getModel('catalog/product')
        ->getCollection()
        ->addAttributeToSelect('*')
        ->setPageSize(200)
        ->setCurPage(1)
        ->setOrder('id', 'ASC')
        ->addAttributeToFilter('status', array('eq' => '1'));
    $doc = new DOMDocument();
    $doc->encoding = 'utf-8';
    $doc->formatOutput = true;
    $root = $doc->createElement("root");
    $doc->appendChild($root);
    $productsX = $doc->createElement("catalog");
    $root->appendChild($productsX);
     foreach ($products as $_product) {
            $product = $doc->createElement("product");
            $id = $doc->createElement("id");
            $id->appendChild(
                $doc->createTextNode($_product->getId())
            );
            $product->appendChild($id);
            $url = $doc->createElement("url");
            $url->appendChild(
                $doc->createTextNode(trim($_product->getData('url_key')))
            );
            $product->appendChild($url);
            $urlPath = $doc->createElement("url_path");
            $urlPath->appendChild(
                $doc->createTextNode(trim($_product->getProductUrl()))
            );
            $product->appendChild($urlPath);
            $title = $doc->createElement("title");
            $title->appendChild(
                $doc->createTextNode(trim($_product->getName()))
            );
            $product->appendChild($title);
            $sku = $doc->createElement("sku");
            $sku->appendChild(
                $doc->createTextNode($_product->getSku())
            );
            $product->appendChild($sku);
            $price = $doc->createElement("price");
            $price->appendChild(
                $doc->createTextNode(trim((int)$_product->getPrice()))
            );
            $product->appendChild($price);
            $formatedprice = $doc->createElement("formated_price");
            $formattedPrice = Mage::helper('core')->currency($_product->getPrice(), true, false);
            $formatedprice->appendChild(
                $doc->createTextNode(trim($formattedPrice))
            );
            $product->appendChild($formatedprice);
            $productsX->appendChild($product);
    }
    file_put_contents($file, $doc->saveXML(), FILE_APPEND);
} catch (Exception $e) {
    echo 'Eroror : - ';
    echo $e->getMessage();
}

With this method, the admin can export Magento products and its data in XML file easily.

Thank you.

Sanjay Jethva Full Image
Article bySanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.