0

I want to fetch all the keywords used in the component content not in the metadata. I am using GetListUsedKeywords() method to get the keywords of the components. I have written a code like below:

XDocument document = null;
XDocument document = XDocument.Parse(compCurrent.GetListUsedKeywords().OuterXml);//ListColumnFilter.XMLListExtended).Replace("tcm:Item", "tcmItem"));

I am getting the result like below in document variable,

<tcm:ListUsedItems xmlns:tcm="http://www.tridion.com/ContentManager/5.0">
  <tcmItem ID="tcm:89-43995-1024" Title="Environment" Type="1024" OrgItemID="tcm:89-6332-512" Path="\120 Rolls-Royce.com Schemas\Sustainability" Icon="T1024L0P0" Publication="120 Rolls-Royce.com Schemas" />
  <tcmItem ID="tcm:89-43996-1024" Title="Communities" Type="1024" OrgItemID="tcm:89-6332-512" Path="\120 Rolls-Royce.com Schemas\Sustainability" Icon="T1024L0P0" Publication="120 Rolls-Royce.com Schemas" />
  <tcmItem ID="tcm:89-48010-1024" Title="Case Study" Type="1024" OrgItemID="tcm:89-7063-512" Path="\120 Rolls-Royce.com Schemas\Functionality Type" Icon="T1024L0P0" Publication="120 Rolls-Royce.com Schemas" />
</tcm:ListUsedItems>

As in this result, The method GetListUSedKeywords() brings all the keywords(in content as well as metadata). I do not want element with Title "Case Study" , as it belongs to metadata of the component.

How can I filter and fetch only the keywords of the component content and not metadata?

is it possible by GetListUsedKeywords(filter) by passing filter to the function?

pls help.

  • Can you give some more detail about the Component and its Schema, from your list I would say that all three of those Keywords are used by the Component. – Bart Koopman Mar 20 '14 at 11:38
  • 1. do you mean "Group" by category in the sentence(because it is actually not in a group of other two elements) ? 2. what do you mean by "Folder" in the sentence (last element in xml, which is coming from the other folder). I guess you mean "Category" here, right? – Saurabh Gangwar Mar 20 '14 at 12:01
  • @SaurabhGangwar, Yes it is a type of Category. – Urvesh Mar 20 '14 at 12:05
  • against which condition(logic) you want to filter out the last Element? – Saurabh Gangwar Mar 20 '14 at 12:09
  • @saurab,@Bart - The actual problem is that the case study is the keyword which is in the metadata of the component. So the method .GetListUSedKeywords brings all the keywords. My component uses 2 keywords and third keyword (case study)which is in the metadata of the component is also coming. How can i filter and fetch only the keywords of the component and not metadata. – Urvesh Mar 20 '14 at 12:18
1

To filter out keywords used in content data, you need to read the schema of the component and go through all the content fields.

if field is using a category, add it to a collection object (string[] CatIDs in the code below). and use it for filtering the xml results.

you can try the below code:

                            string[] CatIDs; // collection of the categories used in conent fields
                            XElement xmlData;
                            xmlData = document.Root;
                            XNamespace ns = xmlData.GetDefaultNamespace();
                            string fieldName = "tcmItem";

//filtering out keywords form the category tcm:89-7063-512
                            var results = xmlData.Descendants(ns + fieldName).Where(i => CatIDs.Contains( i.Attribute("OrgItemID").Value));

the variable results shall contain the filtered elements.

PS: I have not run this code, adjustments could be needed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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