【问题标题】:Error while updating component in Tridion using core service使用核心服务更新 Tridion 中的组件时出错
【发布时间】:2012-05-23 03:47:45
【问题描述】:

使用核心服务更新 Tridion 中的组件时出现错误

根元素必须在命名空间中

我的代码:

ComponentData  component = client.Read(webDavPath, readOptions) as ComponentData;
component = client.TryCheckOut(webDavPath, readOptions) as ComponentData;
//XDocument dom = XDocument.Parse(component.Content);
//// do your modifications to dom
//component.Content = dom.ToString();
doc.Load(filePath);
sw = new StringWriter();
xw = new XmlTextWriter(sw);
doc.WriteTo(xw);
component.Content = sw.ToString();
//client.CheckOut(webDavPath, true, readOptions);
client.Update(component, readOptions);
client.Save(component, readOptions);
client.CheckIn(component.Id, readOptions);

//client.Update(component, new ReadOptions());
// component = client.Update(component, readOptions) as ComponentData;

【问题讨论】:

    标签: tridion


    【解决方案1】:

    向组件添加新字段时,您需要指定架构命名空间。

    您可以在代码中获取架构命名空间,然后在添加新字段时使用它。

    您尚未展示用于更新内容的代码,因此很难在您的问题上下文中向您展示,但下面的示例可能会有所帮助。 (对您来说可能略有不同,因为您从现有组件开始)

    // get namespace from component schema
    SchemaData sd = client.Read(_componentSchemaTcmId, null) as SchemaData;
    XNamespace ns = sd.NamespaceUri;
    
    //create/update content
    XElement contentXml = new XElement(ns + "news");
    contentXml.Add(new XElement(ns + "title", "Title"));
    contentXml.Add(new XElement(ns + "sub_title", "Sub Title"));
    
    component.Content = contentXml.ToString();
    

    另外,我认为你不需要client.Update(component, readOptions);client.Save(component, readOptions);

    如果这没有帮助,请发布您的完整代码。

    【讨论】:

      【解决方案2】:

      您的架构有一些命名空间,例如这是我的架构:

      <xsd:schema elementFormDefault="qualified" targetNamespace="uuid:ce656a4c-71e8-407f-8734-26a60da2440a" xmlns="uuid:ce656a4c-71e8-407f-8734-26a60da2440a" xmlns:tcmi="http://www.tridion.com/ContentManager/5.0/Instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:import namespace="http://www.tridion.com/ContentManager/5.0/Instance"></xsd:import>
      <xsd:annotation>
          <xsd:appinfo>
              <tcm:Labels xmlns:tcm="http://www.tridion.com/ContentManager/5.0">
                  <tcm:Label ElementName="text" Metadata="false">text</tcm:Label>
              </tcm:Labels>
          </xsd:appinfo>
      </xsd:annotation>
      <xsd:element name="Content">
          <xsd:complexType>
              <xsd:sequence>
                  <xsd:element name="text" minOccurs="1" maxOccurs="1" type="xsd:normalizedString">
                      <xsd:annotation>
                          <xsd:appinfo>
                              <tcm:ExtensionXml xmlns:tcm="http://www.tridion.com/ContentManager/5.0"></tcm:ExtensionXml>
                          </xsd:appinfo>
                      </xsd:annotation>
                  </xsd:element>
              </xsd:sequence>
          </xsd:complexType>
      </xsd:element>
      

      注意"uuid:ce656a4c-71e8-407f-8734-26a60da2440a" 这是您的架构的命名空间。你的组件的根元素应该在同一个命名空间中,这里是对应的组件源:

      <Content xmlns="uuid:ce656a4c-71e8-407f-8734-26a60da2440a">
          <text>Some text</text>
      </Content>
      

      如果您的组件的命名空间不正确 - 您将获得与您所拥有的一样的异常。 如果这不能解决您的问题,能否请您发布您的架构和组件源?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-07
        • 2012-04-21
        • 1970-01-01
        • 2012-12-30
        • 2012-11-09
        • 2012-03-25
        • 2012-10-03
        • 1970-01-01
        相关资源
        最近更新 更多