Path

ez projects / sqliimport / forum / general / generic import handler with...

Attention please: Due to restructuring legacy services, the eZ Projects service is going to be discontinued. All the current repositories will be migrated to a new platform. More details will be announced soon.

Generic Import Handler with Mapping Settings File

You need to be logged in to post messages in the forums. New users may register here.

Fraser Hore

Member since:
04 December 2003

Posts: 13

Thursday 14 October 2010 12:11:49 am

This may be part of the longer term plan but it would be great if it was possible to have a feature in the admin interface where you could create import mapping settings for classes.

In the settings one would define:
- an existing class (browse to and select)
- the location of an xml or csv file (browse to and select)
- the path (xpath?) for the xml element(s) which represents the container of what will become a class object
- mappings for each class attribute to an xml atomic value (using xpath statement?)

Taking it one step further, it would be great if the import could be able to import an xml hierarchy of elements and preserve the hierarchy of the newly created class objects in the node tree.

How difficult would this be to implement? Is anything like this planned?

Thanks,

Fraser

Up

Jérôme Vieilledent

Member since:
09 January 2008

Posts: 98

Thursday 14 October 2010 9:20:00 am

Hi Fraser

Your request is interesting, but quite difficult to implement I guess.
If I understand you well, you'd like a feature like in data_import, but more flexible don't you ?

I'm not a fan of defining this kind of settings directly in the admin interface. I'd rather prefer to use a config file, where you could do the mapping.
Moreover, I'm not sure Xpath would be the best choice as you can have many issues when your XML has namespaces for example.

Your idea is really interesting, but I can hardly imagine how to implement it. Could you precise your need a bit please ? Maybe you already have an idea :)
Up

Fraser Hore

Member since:
04 December 2003

Posts: 13

Wednesday 12 January 2011 6:39:26 pm

Hi Jérôme,

Sorry for the long delay in getting back to you on this. Basically the import handler needs to know four things:

1) the xml file to import
2) the elements within the xml that represent the "rows" of data that should become ez Content Objects
3) which ez Content Class to use to create new Content Objects for each "row"
3) how the elements within the "rows" map to the Class Attributes

This information could be defined in a settings file, and set using an controls in the admin interface. This way it would be very easy to import any xml instance. Just navigate to the file to define the path. Enter the path to the repeating elements (rows). Select one of the available content classes. Map row elements to class attributes.

Being able to do this in the admin interface would make it accessible for all the users who don't know PHP and don't want to mess around adding files to the file system. They could do it all very quickly in the admin interface, just like setting up an RSS import. Except that you would have the advantage of importing any xml structure.

For xml structures that are in a tree hierarcy, the handler code could be recursive, grabbing the rows within rows and creating content objects with a location set to the id of the object created for the parent row. Users could even set a depth variable to control how deep in the hierarchy the code would run.

I hope this clarifies what I had in mind.

Cheers,

Fraser
Up

You need to be logged in to post messages in the forums. New users may register here.