Getting additional keyword information from item Xml?



I have a very generic "GetItemXml" template building block that basically reads the current item being rendered and outputs the item's xml to the delivery tier.

Component component = (Component)engine.GetObject(package.GetByName(Package.ComponentName));
output = package.CreateXmlDocumentItem(
           ContentType.Xml,component.ToXml(XmlFormat.R6Native, XmlSections.All)

This outputs the xml correctly, but keyword fields are output like this:


Is there any way - short of controlling the XML output myself - to ask Tridion to include additional information in the XML like an xlink:href to the keyword ID?

Nuno Linhares

Posted 2013-02-20T19:52:15.717

Reputation: 27 884

This answer from @KahTang on StackOverlow is nice as well, though. Then you can use it in your Dreamweaver or xslt Templating as well.

– Hendrik Beenker – 2013-02-21T15:36:01.230



You just need to Load component with proper LoadFlags, like this:

Component component = (Component)engine.GetObject(package.GetByName(Package.ComponentName));
output = package.CreateXmlDocumentItem(
    ContentType.Xml,component.ToXml(XmlFormat.R6Native, XmlSections.All).OwnerDocument);

It will look like this:

<keyword xlink:href="tcm:2-83-1024" xlink:title="b" 

See Coreservice and ReadOptions for more info about LoadFlags

Andrey Marchuk

Posted 2013-02-20T19:52:15.717

Reputation: 9 034

Awesome answer - Really wish I had know this when we built the XSLT Mediator for R5.3 – Chris Summers – 2013-02-21T12:22:55.597

3What? Why is this not in any manual? This has been an issue since R5.3, and people have been coming up with crazy stuff to get this information... – Hendrik Beenker – 2013-02-21T12:52:10.180

Awesome. I now get <ContentCategory xlink:href="tcm:5-239-1024" xmlns:xlink="" xlink:title="tridion 2011">tridion 2011</ContentCategory>

– Nuno Linhares – 2013-02-21T13:55:43.337

2Something about Tridion Nuno didn't know. I'm shocked! – Glenn Stevens – 2013-02-21T14:02:44.843

@user978511, you should update this Stackoverflow question as well, Or redirect it to this answer when the site goes live!

– Hendrik Beenker – 2013-02-21T15:27:47.603

I remember a bunch of helper functions to get that information in additional lines of code... all messy. Great answer! – Mihai Cădariu – 2013-02-22T19:54:05.030