3

How do I get the XML structure of an item in Tridion (like Schema, Component, Compound Template, Keywords, Categories, Folders etc)?

Does it lies in the installation folder of Tridion or anywhere else? Or is there any way to access it from Tridion UI Directly?

m4573r
  • 992
  • 7
  • 17
Patan
  • 17,073
  • 36
  • 124
  • 198
  • It is not clear what XML structure do you want to see. Can you please clarify your question? If you want to get xml of an item, then you can use CoreService API to get it. I believe that the same information you can get by using UI API. – Igor Paniushkin Jun 12 '12 at 07:23
  • @IgorPaniushkin. I want to get the complete source of any item(like Component, Folder, Schema or Category). – Patan Jun 12 '12 at 07:58
  • It would help if you would specify the context. Boris already answered how to do it in Anguilla, Quirijn on how to do it in IE, but you can also do the same with TOM, TOM.NET, XSLT or CoreService - using different methods obviously... – Nuno Linhares Jun 12 '12 at 11:24
  • http://stackoverflow.com/questions/10981052/how-to-get-the-tcm-custom-protocol-handler-working-in-internet-explorer-64-bit – Frank van Puffelen Jun 12 '12 at 13:08

5 Answers5

9

Here is the simplest snippet you can run in browser console to achieve that:

var itemUri = "tcm:...";
var item = $models.getItem(itemUri);
if(item)
{
   if(item.isStaticLoaded())
   {
      console.log(item.getStaticXml());
   }
   else
   {
      $evt.addEventHandler(item, "staticload", function() {
         console.log(item.getStaticXml());
      });
     item.staticLoad();
   }
}
Boris Ponomarenko
  • 1,324
  • 6
  • 7
4

You can use the protocol handler as well. If you are logged in on the content management server, just start internet explorer and type the uri in the address bar. It will display the XML representation of any item. Howvever: this does not work on 64-bit versions of IE 9 (see another recent thread).

Quirijn
  • 3,549
  • 15
  • 30
4

If using the CoreService you can also get an item's XML with the following code:

public XmlElement ToR6Xml()
{
    DataContractSerializer dcs = new DataContractSerializer(ComponentData);
    using(MemoryStream stream = new MemoryStream())
    {
        dcs.WriteObject(stream, CurrentData);
        stream.Position = 0;
        XmlDocument document = new XmlDocument();
        document.Load(stream);
        return document.DocumentElement;
    }
}

This will however return Tridion "R6" Xml, not the same that is exposed through TOM.NET or the protocol handler ("R5" xml).

N

Nuno Linhares
  • 10,214
  • 1
  • 22
  • 42
2

Two more quick ways to get at least component XML, this time via templates.

Caution: be careful with relying on the raw source for items, especially when we there's a supported API instead.

XSLT Component Template

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:generic="http://createandbreak.net/schema/generic" 
    xmlns:tcm="http://www.tridion.com/ContentManager/5.0"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    exclude-result-prefixes="xsl tcm xlink generic">

    <xsl:output omit-xml-declaration="no" indent="yes"
        method="xml" cdata-section-elements="description" />
    <xsl:variable name="Content" select="/tcm:Component/tcm:Data/tcm:Content" />

    <xsl:template match="/">
        <xsl:copy-of select="." />
        <xsl:apply-templates select="$Content/*" />
     </xsl:template>

    <xsl:template match="*">
        <xsl:copy-of select="." />
    </xsl:template>
</xsl:stylesheet>

C# Assembly Template Building Block (TOM.NET)

using Tridion.ContentManager.ContentManagement;
using Tridion.ContentManager.Templating; 
using Tridion.ContentManager.Templating.Assembly;

namespace CreateAndBreakTemplates
{
    [TcmTemplateTitle("Show XML Guts")]
    public class ShowXmlGuts : ITemplate
    {
        public void Transform(Engine engine, Package package)
        {
            Item contentItem = package.GetByType(ContentType.Component);
            Component component = engine.GetObject(contentItem.GetAsSource().GetValue("ID")) as Component;
            package.PushItem("componentSource", package.CreateHtmlItem(component.Content.OuterXml));
        }
    }
}
Alvin Reyes
  • 2,889
  • 16
  • 38
0

As noted by Quirijn, using the protocol handler is a favourite technique. Also - if you're using Tridion 2011, then the Item Xml extension from the http://code.google.com/p/tridion-2011-power-tools/ is very useful too.

If you are on an older version of Tridion, you might also want to try setting the UI into debug mode and examining the XML that way.

Dominic Cronin
  • 6,062
  • 2
  • 23
  • 56