如何使用核心服务在 SDL Tridion 中不加载 XML 的情况下为组件设置内容? [英] How to set content to a component without loading XML in SDL Tridion using core services?

查看:52
本文介绍了如何使用核心服务在 SDL Tridion 中不加载 XML 的情况下为组件设置内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不使用核心服务的 SDL Tridion 中加载 XML 的情况下为组件设置内容?

How do I set content to a component without loading XML in SDL Tridion using core services?

推荐答案

如果您希望通过核心服务创建常规组件,您可以使用 这个辅助类.

If you are looking to create a regular Component through the Core Service, you can avoid having to craft the XML yourself by using this helper class.

有了这个,你可以像这样创建一个组件:

With this you can create a Component like this:

schemaFields = client.ReadSchemaFields("tcm:1-2-8", true, DEFAULT_READ_OPTIONS);
component = (ComponentData)client.GetDefaultData(ItemType.Component, "tcm:1-57-2");

fields = Fields.ForContentOf(schemaFields);

component.Title = "Name of component (created at "+ DateTime.Now + ")";
fields["Title"].Value = "Title of newly created component";
fields["Intro"].Value = "Intro of newly created component";
fields["Section"].AddValue("This is the first section");
fields["Section"].AddValue("This is the section section");

component.Content = fields.ToString();

component = (ComponentData)client.Create(component, DEFAULT_READ_OPTIONS);

这篇关于如何使用核心服务在 SDL Tridion 中不加载 XML 的情况下为组件设置内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆