8

I'm creating a web service in C# for Tridion 2009. This web service creates a schema in Tridion based on an XML input file. The schema gets created just fine. But I can't seem to change the schema namespace. I would like to do this on the moment that I create or update the schema.

From:

<xsd:schema targetNamespace="uuid:C5F06CAA-7C03-40CD-A857-351098D7DD99"

To:

<xsd:schema targetNamespace="http://namespace.mynamespace.nl/content/generiek/1.0"

I'm creating the schema as follows:

schema = (Schema)tdse.GetNewObject(Tridion.ContentManager.Interop.TDSDefines.ItemType.ItemTypeSchema, folderID, publicationID);
            schema.Title = CreateSlugTitle(schema_title_prefix + portletProviderID);
            schema.Description = portletProviderID;
CreateFragmentSchemaFields(schema, tdse, fieldName, fieldType, fieldMandatory, fieldLable);
   protected void CreateFragmentSchemaFields(Schema schema, Tridion.ContentManager.Interop.TDS.TDSE tdse, string fieldName, string fieldType, Boolean fieldMandatory, string fieldLable)
{
    var schemaField = schema.Fields;

    switch (fieldType)
    {
        case "text":
            fieldName = "fragment_text." + CreateSlugTitle(fieldName);
            schema.Fields.AddNew(fieldName);
            schemaField[fieldName].MaxOccurs = 1;
            schemaField[fieldName].FieldType = EnumTridionWebSchemaFieldType.FieldTypeFormatText;
            schemaField[fieldName].Description = fieldLable;
            schemaField[fieldName].FilterXSLT = "";
            schemaField[fieldName].Size = 5;

            if (fieldMandatory)
            {
                schemaField[fieldName].MinOccurs = 1;
            }
            else
            {
                schemaField[fieldName].MinOccurs = 0;
            }
            break;
        case "link":
            embeddedSchema = (Schema)tdse.GetObject(embeddedLinkSchemaID, EnumOpenMode.OpenModeView, null, XMLReadFilter.XMLReadAll);
            fieldName = "fragment_link." + CreateSlugTitle(fieldName);
            schema.Fields.AddNew(fieldName);
            schemaField[fieldName].Description = fieldLable;
            schemaField[fieldName].FieldType = EnumTridionWebSchemaFieldType.FieldTypeEmbed;
            schemaField[fieldName].EmbeddedSchema = embeddedSchema;

            if (fieldMandatory)
            {
                schemaField[fieldName].MinOccurs = 1;
            }
            else
            {
                schemaField[fieldName].MinOccurs = 0;
            }
            break;
    }
}
  • +1 and thanks for joining us on Tridion Stack Exchange. An edit from Frank van Puffelen is a good sign, too. Hey, I recognize that logo! ;-) – Alvin Reyes Mar 8 '13 at 18:04
6

There is a NamespaceURI property but unfortunately it's read-only. So it looks like you will need to use UpdateXML to set it. For that, you would probably have to specify the full XSD -- so you might want to do that after updating all of the fields.

| improve this answer | |
  • Thanks Peter, the NameSpaceURI is read-only in deed. i was hoping there would be a better alternative then updating the XML. – Roel van Roozendaal Mar 8 '13 at 11:31
2

A Quick Try tells me it's not going to work. the namespace gets replaced but the the schema cant be saved.

            //TEST TO CHANGE THE ROOTNAMESPACEURI            
        string changeNameSpace = schema.GetXML(XMLReadFilter.XMLReadAll);
        string NameSpaceID = string.Empty;

        foreach (Match m in Regex.Matches(changeNameSpace, "uuid[\\w\\:\\-]+(\")"))
        {
            NameSpaceID = m.Value.Replace("uuid", "");
            NameSpaceID = m.Value.Replace("\"", "");
            Logger(NameSpaceID);
            changeNameSpace = changeNameSpace.Replace(NameSpaceID, "http://namespace.mywebsite.nl/content/generiek/1.0");
            changeNameSpace = changeNameSpace.Replace("<tcm:NamespaceURI>" + NameSpaceID + "</tcm:NamespaceURI>", "<tcm:NamespaceURI>http://namespace.mywebsite.nl/content/generiek/1.0</tcm:NamespaceURI>");
            changeNameSpace = changeNameSpace.Replace("xmlns=\"" + NameSpaceID + "\"", "xmlns=\"http://namespace.mywebsite.nl/content/generiek/1.0\"");
            Logger(NameSpaceID);
        }

        Logger("xml out: " + changeNameSpace + " end xml out ");
        schema.UpdateXML(changeNameSpace);

ERROR: CDATA[It is not possible to change the NamespaceURI of a Schema]

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.