开发者

How can I change the schema of an existing tridion component

I have some component items in tridion which are set up for a particular schema. I'd like to be able to change the schema for those items to a newer schema. The new schema retains all of the existing properties that the old one had, so there would be no data loss. In this situation it is not possible t开发者_运维百科o just alter the existing schema.

Does anyone know if it's possible to do this?


You can change the schema of a component simply by assigning a new value to the Schema property of the component and saving it. Of course, saving the component will require that the component validates against the new schema.

The trivial case for this is when you've just copy-pasted the schema and therefore both schemas are identical. In practice, you generally have a reason for changing the schema, in which case you probably want to use GetXml() and UpdateXml() on the component and have an XSLT transform the XML to something compliant with the new schema. In this scenario, you can simply update the schema reference in your XSLT.

As Jonathon says, you can use a custom page for this, but bear in mind that generally this is a one-time action which should be designed/executed by programmers and administrators, so if you use a custom page, you probably want to remove it afterwards.


There is a reason why the Tridion GUI does not allow you to change the schema on a component: it is very likely that your component will lose its content after such a change, even if the two schemas have some fields in common. To avoid this, make sure that the schemas have the same target namespace. In that case, if a field is defined in both schemas, the component will retain its values even after the schema has been changed.


The Tridion Content Porter lets you export content and schemas from one CMS to another. It can also be used to move items between publications. This is one option to "duplicate" a schema and its content for re-use (as well as to backup any work before changing live data!).

Be careful not to change the namespace or any XML fields you'd like to keep (descriptions and schema name are okay though). To be sure, especially with live data, do a clean export just in case before using any of these answers.


It is not possible to change the Schema of a Tridion Component through the Content Manager interface. However, this can be achieved using a 'Custom Page' as the API allows the changing of a Component's Schema through code.

Taken from the SDL Tridion 2009 documentation (Templating Implementation Manual (TOM.NET) 2009):

  • Class: Tridion.ContentManager.ContentManagement.Component
  • Property: public Schema Schema { get; set; }
  • Description: Get or set the Schema for the Component's content and metadata.

There is an item (including a code sample) on the Tridion developer forums (TOPIC_ID=2899) about this. However, as this is a closed forum I am unsure about the legalities of reproducing the code here.


I was able to do this by writing some queries to replace the schema names and references directly within the tridion database. It worked fine, but I would only recommend this if the starting schema is EXACTLY like the end schema. Otherwise it'll break the components.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜