简体   繁体   English

将Tridion组件转储为XML

[英]Dump Tridion Component as XML

What is the simplest way of dumping Tridion component content (based on a given schema, ie: non-arbitrary) into XML using modular template? 使用模块化模板将Tridion组件内容(基于给定模式,即:非任意)转储到XML中的最简单方法是什么?

Specifically, need to pass component's content to/as ASP.Net custom control, that is, something like: 具体来说,需要将组件的内容传递给/作为ASP.Net自定义控件,即:

<custom:MyControl runat="server"
    TextField="value1"..>
  <EmbeddedField>
    ..
  </EmbeddedField>
</custom:MyControl>

I see one possible way would be to tweak Default Dreamweaver Component Design DWT TBB, but that seems to be too laborious. 我看到一种可能的方法是调整Default Dreamweaver组件设计 DWT TBB,但这似乎太费力了。

EDIT 编辑

Another murky subject was the second part of the question above: embedding XML into ASP.Net control markup. 另一个模糊的主题是上面问题的第二部分:将XML嵌入到ASP.Net控制标记中。 The problem is that XML needs to be escaped. 问题是需要转义XML。 The following brainteaser does it in a DWT (pressuming, that Nuno's TBB wrote into Output): 下面的脑力激荡器在DWT中进行(压力,Nuno的TBB写入输出):

<custom:MyControl runat="server">
    <xml>
        @@(Output).replace(RegExp.call(null, /&/.toString()[1], "g"), '&').replace(RegExp.call(null, /</.toString()[1], "g"), '<').replace(RegExp.call(null, />/.toString()[1], "g"), '>').replace(RegExp.call(null, String.fromCharCode(34), "g"), '"')@@
    </xml>
</custom:MyControl>

(All that ado is only necessary to overcome DWT's arcane JS escaping rules.) (所有这些只是克服DWT神秘的JS转义规则所必需的。)

Create ac# Template Building Block with the following code in it: 使用以下代码创建ac#Template Building Block:

TemplatingLogger log = TemplatingLogger.GetLogger(GetType());
if (package.GetByName(Package.ComponentName) == null)
{
    log.Debug("Not running in a Component Template, exiting.");
    return;
}
Component component = (Component)engine.GetObject(package.GetByName(Package.ComponentName));
package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.Xml, component.Content.OuterXml));

And use it in your template without any other building blocks. 并且在您的模板中使用它而不需要任何其他构建块。

This will output the exact content of Component.Content , which is rarely what you really want (for instance, how do you deal with binaries or linked components?), so you'll want to evolve to something else, with more details, and possibly removing the namespace from the XML nodes too... 这将输出Component.Content的确切内容,这很少是你真正想要的(例如,你如何处理二进制文件或链接组件?),所以你需要进一步发展到其他东西,更多细节,以及可能也从XML节点中删除命名空间......

i typically use a large switch(field.GetType().Name) and then deal with each field type as appropriate, something along these lines: 我通常使用一个大型switch(field.GetType().Name) ,然后根据需要处理每个字段类型,这些内容如下:

foreach (ItemField field in content)
{
    string fieldType = field.GetType().Name;
    switch (fieldType)
    {
        case "XhtmlField":
            // do something, like write it to an XmlWriter
            break;

And so on and so forth. 等等等等。

I would use the XSLT mediator and then make an XSLT TBB using <xsl:copy-of select="."/> 我将使用XSLT介体,然后使用<xsl:copy-of select="."/>创建一个XSLT TBB <xsl:copy-of select="."/>

If you don't have the XSLT Mediator installed, it will be simpler to write a C# TBB with outputs the .Content property of the Component to the package with the name Output. 如果您没有安装XSLT介体,则编写C#TBB会更简单,并将Component的.Content属性输出到名为Output的包。 See Nuno's code sample for more details. 有关更多详细信息,请参阅Nuno的代码示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM