我在使用核心服务更新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;
Run Code Online (Sandbox Code Playgroud)
在向组件添加新字段时,需要指定架构命名空间.
您可以在代码中获取架构命名空间,然后在添加新字段时使用此命名空间.
您没有显示用于更新内容的代码,因此很难在问题的上下文中向您展示,但下面的示例可能有所帮助.(当你从现有组件开始时,它可能略有不同)
// 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();
Run Code Online (Sandbox Code Playgroud)
另外,我不认为你需要同时client.Update(component, readOptions);和client.Save(component, readOptions);
如果这没有帮助,请发布您的完整代码.
| 归档时间: |
|
| 查看次数: |
1055 次 |
| 最近记录: |