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);
}
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With