19

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)
                                                                .OwnerDocument);

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

<ContentCategory>tridion</ContentCategory>
<ContentCategory>tridion2009</ContentCategory>

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?

1
  • This answer from @KahTang on StackOverlow is nice as well, though. Then you can use it in your Dreamweaver or xslt Templating as well. Feb 21, 2013 at 15:36

1 Answer 1

25

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

Component component = (Component)engine.GetObject(package.GetByName(Package.ComponentName));
component.Load(LoadFlags.KeywordXlinks);
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" 
         xmlns:xlink="http://www.w3.org/1999/xlink">b</keyword>

See Coreservice and ReadOptions for more info about LoadFlags

6
  • Awesome answer - Really wish I had know this when we built the XSLT Mediator for R5.3 Feb 21, 2013 at 12:22
  • 3
    What? 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... Feb 21, 2013 at 12:52
  • Awesome. I now get <ContentCategory xlink:href="tcm:5-239-1024" xmlns:xlink="w3.org/1999/xlink" xlink:title="tridion 2011">tridion 2011</ContentCategory>
    – Nuno Linhares
    Feb 21, 2013 at 13:55
  • 2
    Something about Tridion Nuno didn't know. I'm shocked! Feb 21, 2013 at 14:02
  • @user978511, you should update this Stackoverflow question as well, Or redirect it to this answer when the site goes live! Feb 21, 2013 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.