Philippe Bénard
Software Architect

Intelligent xml import in sitecore


In my position as Software Architect and Software engineer I frequently face the requirement to import for example product information from third-party systems such as SAP into sitecore.

The preferred format is XML in this case as sitecore is based on XML.

As everyone knows, requirements change during agile development due to the software and structure and the final data structure only becomes clear during the different development phases. The outcome of this is that an import of product information could become a bottleneck. However, the product information should be integrated in the first steps rather than along the line.

The aim should be to get a flexible and dynamic import to avoid putting in excessive effort when changes appear and to avoid increasing project costs to the customer.

Therefor we need an XML structure that gives us this flexibility. It should always be define prior the project kick-off.
The XML offered here contains some static branches and flexible branches named “attribute” and “attributegroup”. In this post you will learn how to add items to sitecore and how to create sitecore-templates dynamically by using XML and c#.

1.) Define your xml - click here for download
The structure is very simple. You got one or more categories with a unique key and a name, which contains products with some static values like “name”, “identifier”(unique), prices and images(the latter two are not considered in this example). The product also contains a tag “attributes” which describes our dynamic section. In the following steps we will create templates from this section by using the first level “attributegroup”-Tag as sitecore-Template, the secondlevel “attributegroup”-Tag as sitecore-Template section and the “attribute” as sitecore-Field value.

2.) Create base product/category template and productsBranch
To import the categories and products into sitecore you need to define/create a branch where the items should be added. You need a template for the product and category.

Producttemplate:

Categorytemplate:

Branch:

3.) Create an object in c# which is equivalent to the XML - click here for download
You need to create an object in c# with which you can work in further steps.

4.) Load and Parse XML - click here for download
Load your XML and parse it to your object.

5.) Importmanager - create or update categories
First of all create or update categories as described in the following snippet - click here for download

6.) Create or update products - click here for download

7.) Create or update templates click here for download
Create or update the sitecore-Templates based on the “attributes”-Tag children.

8.) Add attributes click here for download

That’s it - the finished result should be something like this






Kommentare
1

Amit Celly

Hi Philippe, Thanks for sharing the solution. I am trying to implement the above mentioned steps but facing kind of issue in implemtnation. Below are the few points to highlight. 1. Define your xml - click here for download is linked to "http://www.netzkern.de/~/media/images/smub/blog-post-images/fakeproduct.ashx" and not to an actual XML file. Would be great if you may please share the XML format to be used for implementation. 2. Add attributes - click here for download What templates are used to create ATTRIBUTE_GROUP1 and ATTRIBUTE_GROUP2 templates. As these templates are not there is package that was attached. It would be great if you may also descripbe the process to execution. Regards, Amit Celly

am 04.10.2013

2

Philippe Bénard

Hi Amit, please try this link http://www.netzkern.de/~/media/images/smub/blog-post-images/fakeproductxml.ashx regarding the xml. The Template fpr Attribute_Group1 and Attribute_Group2 are inserted dynamically thatmeans these fields are build up during import. The process is mentioned in the Blogpost: .) Create an object in c# which is equivalent to the XML - click here for download You need to create an object in c# with which you can work in further steps. Load and Parse XML Importmanager - create or update categories Create or update products - click here for download Create or update templates Add attributes Best regards, Phil

am 04.10.2013

3

Amit Celly

Hi Philippe, Thanks for updates on the solution. Do you have any video on the same solution? If yes, please do share the link for the reference. Regards, Amit Celly

am 04.10.2013

4

Amit Celly

Hi Philippe, Thanks for updates on the solution. Do you have any video on the same solution? If yes, please do share the link for the reference. Regards, Amit Celly

am 04.10.2013

5

Amit Celly

Hi Phil, Fortunately, I am able to figure out the working of solution. Though I still have a question why price field Type under Base Product Template is used as Treelist? Regards, Amit Celly

am 05.10.2013

Kommentar hinzufügen
Vor und Zuname
E-Mail
E-Mail bei weiteren Kommentaren
Mein Kommentar