2

I have a new namespace for my Structure Group metadata schema and I want to update all my Structure Groups using this metadata schema to the use the new namespace. I am using Elena's script here.

However, I have an error when trying to save a Structure Group. I want to use client.Update(data, ReadOptions) where data is the Metadata XML of the StructureGroup. However, it fails even when I try not updating anything, and just getting and savign the same content to the item. Here is my code and below my error. I have no idea how to get the extra info the core service wants in the xml so I can simply replace the namespace on the Structure Group metadata.

This also occurs with a Page as well.

XSD:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="uuid:68785a26-2757-4cb0-9747-5224ec9e3215" xmlns:tcmi="http://www.tridion.com/ContentManager/5.0/Instance" xmlns:category="tcm:0-9-1/Categories.xsd" elementFormDefault="qualified" targetNamespace="uuid:68785a26-2757-4cb0-9747-5224ec9e3215">
  <xsd:import namespace="http://www.tridion.com/ContentManager/5.0/Instance" schemaLocation="cm_xml_inst.xsd"></xsd:import>
  <xsd:include schemaLocation="tcm:9-7887-8"></xsd:include>
  <xsd:import namespace="tcm:0-9-1/Categories.xsd" schemaLocation="tcm:0-9-1/Categories.xsd"></xsd:import>
  <xsd:include schemaLocation="tcm:9-7628-8"></xsd:include>
  <xsd:annotation>
    <xsd:appinfo>
      <tcm:Labels xmlns:tcm="http://www.tridion.com/ContentManager/5.0">
        <tcm:Label ElementName="seo" Metadata="true">Search Engine Optimisation</tcm:Label>
        <tcm:Label ElementName="theme" Metadata="true">Theme</tcm:Label>
        <tcm:Label ElementName="header" Metadata="true">Header</tcm:Label>
        <tcm:Label ElementName="sections" Metadata="true">Page sections</tcm:Label>
        <tcm:Label ElementName="footer" Metadata="true">Footer</tcm:Label>
      </tcm:Labels>
    </xsd:appinfo>
  </xsd:annotation>
  <xsd:element name="Metadata">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="seo" minOccurs="0" maxOccurs="1" type="seo">
          <xsd:annotation>
            <xsd:appinfo>
              <tcm:ExtensionXml xmlns:tcm="http://www.tridion.com/ContentManager/5.0"></tcm:ExtensionXml>
              <tcm:EmbeddedSchema xmlns:tcm="http://www.tridion.com/ContentManager/5.0" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="tcm:9-7628-8" xlink:title="Search Engine Optimization Metadata"></tcm:EmbeddedSchema>
            </xsd:appinfo>
          </xsd:annotation>
        </xsd:element>
        <xsd:element name="theme" minOccurs="0" maxOccurs="1" type="category:section-homepage-themes">
          <xsd:annotation>
            <xsd:appinfo>
              <tcm:ExtensionXml xmlns:tcm="http://www.tridion.com/ContentManager/5.0"></tcm:ExtensionXml>
              <tcm:Size xmlns:tcm="http://www.tridion.com/ContentManager/5.0">1</tcm:Size>
              <tcm:listtype xmlns:tcm="http://www.tridion.com/ContentManager/5.0">select</tcm:listtype>
            </xsd:appinfo>
          </xsd:annotation>
        </xsd:element>
        <xsd:element name="header" minOccurs="0" maxOccurs="1" type="tcmi:SimpleLink">
          <xsd:annotation>
            <xsd:appinfo>
              <tcm:ExtensionXml xmlns:tcm="http://www.tridion.com/ContentManager/5.0"></tcm:ExtensionXml>
              <tcm:linktype xmlns:tcm="http://www.tridion.com/ContentManager/5.0">ComponentLink</tcm:linktype>
              <tcm:AllowMultimediaLinks xmlns:tcm="http://www.tridion.com/ContentManager/5.0">false</tcm:AllowMultimediaLinks>
              <tcm:AllowedTargetSchemas xmlns:tcm="http://www.tridion.com/ContentManager/5.0">
                <tcm:TargetSchema xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="tcm:9-5877-8" xlink:title="Page Header"></tcm:TargetSchema>
              </tcm:AllowedTargetSchemas>
            </xsd:appinfo>
          </xsd:annotation>
        </xsd:element>
        <xsd:element name="sections" minOccurs="0" maxOccurs="unbounded" type="tcmi:SimpleLink">
          <xsd:annotation>
            <xsd:appinfo>
              <tcm:ExtensionXml xmlns:tcm="http://www.tridion.com/ContentManager/5.0"></tcm:ExtensionXml>
              <tcm:linktype xmlns:tcm="http://www.tridion.com/ContentManager/5.0">ComponentLink</tcm:linktype>
              <tcm:AllowMultimediaLinks xmlns:tcm="http://www.tridion.com/ContentManager/5.0">false</tcm:AllowMultimediaLinks>
              <tcm:AllowedTargetSchemas xmlns:tcm="http://www.tridion.com/ContentManager/5.0">
                <tcm:TargetSchema xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="tcm:9-5880-8" xlink:title="Page Section"></tcm:TargetSchema>
                <tcm:TargetSchema xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="tcm:9-5872-8" xlink:title="CTA Collection"></tcm:TargetSchema>
              </tcm:AllowedTargetSchemas>
            </xsd:appinfo>
          </xsd:annotation>
        </xsd:element>
        <xsd:element name="footer" minOccurs="0" maxOccurs="1" type="footer">
          <xsd:annotation>
            <xsd:appinfo>
              <tcm:ExtensionXml xmlns:tcm="http://www.tridion.com/ContentManager/5.0"></tcm:ExtensionXml>
              <tcm:EmbeddedSchema xmlns:tcm="http://www.tridion.com/ContentManager/5.0" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="tcm:9-7887-8" xlink:title="Simple Page Footer"></tcm:EmbeddedSchema>
            </xsd:appinfo>
          </xsd:annotation>
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

Error Message

  > > XML validation error. Reason: The required attribute
    > > 'http://www.w3.org/1999/xlink:href' is missing..
    > 
    > "<Metadata
    > xmlns=\"uuid:68785a26-2757-4cb0-9747-5224ec9e3215\"><header><title>SG
    > title..</title></header></Metadata>"

Code:

CoreServiceClient client = new CoreServiceClient("basicHttp_2012");
string userName = "robertc";
string password = "pass";
var credentials = CredentialCache.DefaultNetworkCredentials;
if (!string.IsNullOrWhiteSpace(userName) && !string.IsNullOrWhiteSpace(password))
{
    credentials = new NetworkCredential(userName, password);
}
client.ChannelFactory.Credentials.Windows.ClientCredential = credentials;

ReadOptions readOptions = new ReadOptions();

string sg = "tcm:10-24482-4";
RepositoryLocalObjectData data = (RepositoryLocalObjectData)client.Read(sg, readOptions);
string meta = data.Metadata;
XmlDocument xml = new XmlDocument();
xml.LoadXml(meta);
string metadata = data.Metadata;                
data.Metadata = metadata;
try
{
    client.Update(data, readOptions);
}
catch (Exception ex)
{

}

XSD:

6
  • Can you add what data.Metadata currently contains to the question? Apr 9, 2014 at 17:09
  • Are you able to update the metadata using Tridion Explorer? also what kind of fields are Header and Title? Apr 9, 2014 at 17:39
  • It might be the case that in your schema, text field was changed from text to link, or something like this. Could you please post XSD of your schema? Apr 10, 2014 at 6:31
  • It is possible the field type was changed. Another developer worked on it and has been making the changes to the schemas, and content porting them(!). I tested data.Metadata with empty fields and also some filled out. Same results. I am able to update through CME.
    – robrtc
    Apr 10, 2014 at 8:31
  • Sorry, it is not possible to save with the GUI. Hmmm
    – robrtc
    Apr 10, 2014 at 8:41

1 Answer 1

2

The code was OK. However, a linked Multimedia Schema had an incorrect namespace and this was the root cause of the error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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