November Happy Hour will be moved to Thursday December 5th.

Import XML Data To EpiServer

Vote:
 

I have Xml file. Format lilke given below

.......

.......

.

.

.

.

please suggest me how can i import these data into my episerver..

#139268
Sep 29, 2015 8:39
Vote:
 

That was a short and vague description... Can you explain what you are trying to accomplish?

#139269
Sep 29, 2015 8:45
Vote:
 

One simple approach would be to use a ScheduledJob.

Create an XMLReader or deserialize the xml and loop the contents.

Then use the IContentRepository service to save the data into EPiServer.

Ps. Will not send code...

#139270
Edited, Sep 29, 2015 8:53
Vote:
 

Google is your friend, Dinesh. 

You'll find many examples online on how to read from an XML file: http://csharp.net-tutorials.com/xml/reading-xml-with-the-xmlreader-class/

And examples on World on how to create a scheduled job: http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-CMS/8/Scheduled-jobs/Scheduled-jobs/

And how to create pages programatically (in the scheduled job): http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-CMS/7/Content/Pages-and-Blocks/How-To/Creating-a-Page-Programmatically/

That should get you started.

#139277
Sep 29, 2015 9:39
Vote:
 

Hi All,

Thanks for your prompt replies. Actually my requirement is i need to import an XML file data to episerver project. I know how to import XML data to sqlserver using csharp coding but i don't know how to mind columns values in episerver page type columns to the XML columns thats why i posted a question here. Let me explain my requirement once again

1) I have an XML file with lot of products info

2) I have a page type " Products" with some custom fields on episerver

3) How can i set the value of product category,product title fields on episerver programmatically?

Thanks
Dinesh

#139323
Sep 30, 2015 7:50
Vote:
 

Hi again Dinesh, 

It is not recommended to access the database directly and set the property values.

The database in itself has a rather complex relation between pages, its properties, culture specific values and versioning and this is handled by EPiServers APIs.


You need a way to match your xml-data to the content inside EPiServer. What are your identifiers?

1. Use IContentRepository.Load() method or other means to load the matching instance of the page type "Product" that is already stored.
    (This is probably going to be the tricky step, since I'm guessing there is no clean relation between your xml and the EPiServer data)

2. Then get a writeable version by calling page.CreateWriteableClone();

3. Set the properties on it.

4. Then use IContentRepository.Save() to save it back with the modified properties.

#139324
Sep 30, 2015 9:20
Vote:
 

Are you trying to import to a Commerce site or do you a product page type in your cms solution?

If you are working on a CMS site, then do as Arild and Sven-Erik writes. You should not push data straight to the database, use the API.

If you are working with a Commerce site, you should use the file import in the commerce manager. There are some good tips here: https://www.epinova.no/blog/arve-systad/dates/2014/11/episerver-commerce-essentials-4-import-from-external-systems/

#139335
Sep 30, 2015 11:03
Vote:
 

Hi,

This looks not like a Commerce data file (either catalog or BusinessFoundation object).

It depends on what you want to achieve, but basically you can read the data from the XML file, then use IContentRepository to create/update the contents you want. Yes, we highly recommend to not manipulate databases directly. 

An example:

var contentRepo = ServiceLocator.Current.GetInstance<IContentRepository>();
var product = contentRepo.GetDefault<ProductContent>(parentLink); //parentLink is the ContentReference of the Category this product will belong to

product.Code = ...//value read from xml

product.Name = ...//value read from xml

....

contentRepo.Save(product, SaveAction.Publish, AccessLevel.None);

Regards,

/Q

#139337
Sep 30, 2015 11:39
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.