Importing XML Data that contains varying levels of grouping

XML data that contains categories and sub categories can be imported into EasyCatalog using the XML Data Provider module.  Sometimes, records may appear at different levels in the hierarchy of the XML (e.g. some products may be in a category > sub category > sub-sub category structure, others may be in at the category > sub category level).

In the following example, two products can be found under Category 1 > Category 2 > Category 3 (i.e. three levels down), and another product can be found two levels down (Category 4 > Category 5).

To overcome this, a field needs to be configured for each of the possible levels in the hierarchy that we can later group the panel by.  For example, if you know that your structure will only ever contain a maximum of five grouping levels, five fields will need to be configured in the XML data source configuration.

The record XPath in this case would be:

This will ensure that we create a row in the panel for each <product> node in the XML.  In order to group the data, we also need category information which can be retrieved from walking up the XML hierarchy from the <product> node:

However, this will only give the name of the category immediately above in the structure and can not work when there could be a varying number of <category> nodes above.  To overcome this, XPath’s ancestor:: functionality can be used to create fields we can group the panel by:

group 1

group 2

group 3

group 4

 

Data_Source_Configuration_and_Untitled-1___2036_-2

The panel can now be grouped by these fields.

Untitled-1___2400_