How to import XML to Magento 2

- Fire development, Magento 2

Magento 2 Development; Magento 2 tutorial

We all know that Magento 2 supports CSV import/export by default, but what if you need to transfer data via XML? Below, we shed light on how to achieve this goal. More useful Magento 2 guides, advice, and tips are gathered in our Magento 2 Developer’s Cookbook. If you need advanced import functionality, check our Improved Import extension. But let’s return to our mutton.

There is only one way to achieve this goal without using third-party modules. You need a tool that converts XML to CSV. Check this service or this one. Next, you should import a sample CSV file from Magento 2 and compare it with the converted one. If there are any inaccuracies in your CSV file, it is necessary to fix them. Otherwise, you won’t import the necessary data to Magento 2.

Make sure to read the Guide List we have composed for you on how to properly compose and edit a CSV table and what attributes Magento 2 requires for import:

Read Magento 2 import guide list

There is another option though – you can import XML with the help if Improved Import and Export extension that we (FireBear Studio) have developed and keep updating with new features.

Download / Buy Firebear Improved Import / Export Magento 2 Extension

The latest release of the extension added XSLT transformation, to further complement XML file import. XSLT for Magento 2 allows to transform XML files to the formatting accepted by Magento 2. Read more about XSLT transformation.

But first things first. Let’s talk about how can one import XML files into a Magento 2.

How to import XML into Magento 2

To import XML files into Magento 2 you will need two things:

  • Installed Improved Import and Export extension
  • And XML file you want to import

No more no less. If you are reading this article you probably have an XML file, so let’ focus on how to setup and configure the extension.

Step 1: create an import job

Import Import and Export extension operates with jobs. Job is an automated ‘rule’ that dictates the extension when and on which conditions a particular file can be imported.

Both import and export jobs for Magento 2 can be located under System > Improved Import/Export > Import/Export Jobs of your Magento 2 administrator panel.

The first screen you see is the jobs grid. Here you can create, manage and delete any import or export jobs. To create a new job click ‘Add New Job’ button in the upper-right corner of the screen.

Step 2: configure general job settings

In this article we will only cover the basic aspects of configuring the job. If you want more thorough instructions on how to work with the extension – read Improved Import and Export manual.

First you are suggested to name the job, setup the schedule if any, and decide whether you want to reindex the store after the import is done and get rid of possible URL conflicts with Generate Unique Url if Duplicate setting (read more about the error).

Once done with the General Settings you are suggested to specify the entity you want to import. In addition to default entities Magento 2 offers, the extension allows you to import such entities as: CMS pages, cart price rules, categories and other.

After an import entity is selected you can specify separators for the table you are importing. This can be helpful as Magento 2 can only accept CSV tables of particular formatting. However, as we are import XML table we will pass this step.

Now you are suggested to specify the source you will be importing from. Here Improved Import and Export offers quite a number. You can import files from Google Sheets, FTP/SFTP, Dropbox, direct URL or from the local file.

When you specified the path to the XML file you will be importing you will need to hit ‘Validate file’ button. The extension will scan the file to find the imported entities. If everything is fine the rest of the job settings will appear.

Step 3: XSLT transformation

By default the extension support XML tables of the following formatting:

  • XML 1.0
  • encoding: UTF-8
  • field separator: space
  • first row: column names
  • top-level root name: Items
  • XML record name: item

However, with XSLT transformation you can pretty much ignore these, as the XSLT language allows you to transform the XML table into pretty much anything you want.

To give you an example, let’s import a custom XML table. This very table uses custom names for product attributes and custom formatting. You can get it from FireBear Studio GitHub.

Now, to transform this XML into the appropriate format we will need to use and XSLT template. You can think of the template as a set of instructions for the XML on how to behave and how to look. The same XSL file can be found at FireBear Studio GitHub.

To apply the XSLT template, scroll down to the XSLT Configuration section of the new import job screen. Here you will need to enable the XSLT transformation and paste the XSLT template. Once done hit ‘Test XSL Template’ button. The extension will do the necessary tests.

If you are not sure how to compose an XSLT template, or require any assistance – feel free to contact FireBear support team:

Send us a message

We can compose XSLT template for you!

Now, let’s move to the final step of XML file import.

Step 4: run the import job

That’s pretty much it. The only thing you are left to do is to click big orange ‘Save & Run’ button. The extension will import the XML file with proper formatting.

Remember, if you require assistance with your custom XML files and composing XSLT template – contact FireBear support team. We will help you compose proper XSLT template and make sure the XML table is imported into your store.

Download / Buy Firebear Improve Import Magento 2 Extension