Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tridion Core Service Update Error

On a refactoring exercise we are working on, we have to change Page Templates for select websites. Most page get localized and have their page templates updated by the code below but for a few we get the following error:

XML validation error. Reason: The element 'Metadata' in namespace 'uuid:940d95aa-fcce-481c-8de5-c61d06c74f46' has invalid child element 'description' in namespace 'uuid:940d95aa-fcce-481c-8de5-c61d06c74f46'. 

List of possible elements expected: 'TitleSEO, KeywordsSEO, DescriptionSEO, omniture' in namespace 'uuid:940d95aa-fcce-481c-8de5-c61d06c74f46'. 

There is no description field in our metadata schema and TitleSEO, KeywordsSEO, DescriptionSEO, omniture are all optional fields which are not being changed by the code .

try
{
   pData = client.Read(page.Attribute("ID").Value, null) as PageData;
    //Localize Page
    if (!(bool)pData.BluePrintInfo.IsLocalized)
    {
        client.Localize(pData.Id, new ReadOptions());
        if (dTemplateIDs.ContainsKey(pData.PageTemplate.IdRef.ToString()))
        {
            pData.IsPageTemplateInherited = false;
            pData.PageTemplate.IdRef = dTemplateIDs[pData.PageTemplate.IdRef];
            client.Update(pData, new ReadOptions());
        }
    }
}
catch (Exception ex)
{
    Console.WriteLine("Error Inner " + ex.Message);
} 
like image 923
user1949001 Avatar asked Jan 23 '13 16:01

user1949001


2 Answers

It sounds like at some point in the past there was a field in your page metadata schema called "description" (which I suspect was later changed to what is now "DescriptionSEO"). These few pages that cause the error have probably not been updated since the change, and so have the old metadata field in their XML, hence the validation problem when you come to change the Page Template.

If it's only a few pages, just open the pages, add some description or otherwise change something, save them and then try your code again.

If it's more than a few, you'll probably need to detect and remove the existing data programmatically.

like image 112
David Forster Avatar answered Nov 01 '22 05:11

David Forster


I am not sure which version of SDL Tridion you are using, but in some early versions of SDL Tridion 2011, if Metadata had previously been added to any object, it was not cleared by changing the Metadata Schema to be empty on the object. As such, I have found that you had to set the Metadata value to NULL with code before saving the item. This may solve your problem.

like image 34
Chris Summers Avatar answered Nov 01 '22 06:11

Chris Summers