使用核心服務爲Tridion 2011項目編寫自定義導入工具時嘗試保存組件時遇到問題。Tridion 2011核心服務:無法使用Xml操作更新具有新字段的組件
以下代碼在組件上的字段具有值但沒有出現錯誤時正常工作。
這裏是我的代碼(錯誤處理的簡潔,刪除):
//component is a ComponentData object from Tridion
var doc = new XmlDocument();
doc.LoadXml(component.Content);
var namespaces = new XmlNamespaceManager(doc.NameTable);
namespaces.AddNamespace("ns", doc.DocumentElement.NamespaceURI);
//componentFromSpreadsheet has a dictionary of fields and values to update
foreach (var field in componentFromSpreadsheet.Fields)
{
XmlNode xmlNode = doc.SelectSingleNode("//ns:" + field.Key, namespaces);
if (xmlNode == null)
{
xmlNode = doc.CreateNode(XmlNodeType.Element, field.Key,
doc.DocumentElement.NamespaceURI);
doc.DocumentElement.AppendChild(xmlNode);
}
//Namespace any Html in the field
string fieldValue = HtmlTidy.Tidy(field.Value);
xmlNode.InnerXml = fieldValue;
}
component.Content = doc.OuterXml;
//This line throws a FaultException<CoreServiceException> with an
//XmlException from tridion
client.Save(component, null);
下面是從外表套上消息:
在命名空間 元素 '內容'「UUID:09ed2feb-f7cb-4760 -ba4c-b9ff4f45d025'在命名空間'uuid:09ed2feb-f7cb-4760-ba4c-b9ff4f45d025'中具有無效的子元素 'summary'。 'related_links' 在命名空間 'UUID:09ed2feb-f7cb-4760-ba4c-b9ff4f45d025' 預期可能元素的 名單
我知道摘要此組件的架構有效的字段。
看起來模式是嚴格的並且關心Xml中字段的順序。有沒有解決這個問題或其他方法的方法?
在一位同事的(Ryan Durkin)建議中,我們使用了序列化方法,該方法效果很好,且強類型化,但不靈活,所以我們需要同意我們將要更新的模式。 – 2012-03-09 08:02:53