Tuesday, September 30, 2014

Manually Importing Tridion Schemas - But it's turtles all the way down!

Every so often in order to validate some content or troubleshoot an issue, I need to recreate the content in a different system.  This is actually a deconstruct and reconstruct process of taking the schemas apart and re-building them in Tridion.

The best thing to have are the XSDs, all the schemas the content is based on, in xml format.  However, even if this is not entirely the case, it may still be possible to import enough to recreate a given issue.  This does get a little tricky at times because of possible relations pre-existing in schemas such as other embedded schemas, linked components (full schemas) or categories and keywords.

These clever turtles all the way down (read relationships) can be noticed with a quick xml scan in the XSD's available for:
1. WebDAV urls
2. TCM URIs (tcm:x-y-z)

Also look for the lack of the "targetNamespace" attribute in the very first <xsd:schema> node as this will indicate an embedded schema.

Review all schemas available and choose the ones without any relationships, import these first.  
Embedded schemas are also good candidates and as mentioned before you can tell them apart immediately by the lack of the "targetNamespace" attribute.
Next, move over to generic content schemas, and again look to determine what is not referenced by any other schemas, or otherwise follow component links to find the furthest relations.

Once you think you have a plan, and possibly by now have drawn a little pyramid of the schemas relations model, move on to the Content Manager Explorer.

In the Tridion CME, proceed to 
  • Create a new schema and open the source tab
  • Copy the xml to be imported from the original source, paste it in the new schema source and update the namespace with the one from the new schema
  • Switch to the Design tab to see if the xml is recognized and translated into the equivalent fields
  • If yes, great, save the schema
  • If not, figure out what dependencies are missing and either import them or remove them to go on

If some dependencies are missing, don't give up, it may still be possible to partially import what is available.
For instance, if categories are not available, remove these references from the top and carefully remove the associated field(s) so as to preserve the integrity of the xml.  I usually try and re-save the schemas right after such a change in case there is a mistake, because then I will immediately know where I made it!

For example, look for lines such as this:
<xsd:import namespace="tcm:0-5-1/Categories.xsd" schemaLocation="/webdav/010_Schemas/Categories.xsd" />

.. with the corresponding..
 <xsd:element name="Tags" minOccurs="0" maxOccurs="1" type="category:Specific_Category_Name">

Once you have saved all schemas in the CMS, yes, do believe it's possible - this is actually a key component of achieving this, continue on to create some content based on them.  It may take a few tries, quite a bit of patience and definitely plenty determination, but it's been tried, delivered and certainly found useful!