0

Tridion2013. Can someone provide example of core service code retrieving list of metadata fields of a component from multiple folders. Instead of hardcoding the metadata field name, I would like to retrieve all metadata fields from the component.

1
  • Hi, welcome to Tridion and welcome to stackexchange. The best way to get a good answer is to follow the guidelines around asking. Here is a link to get you started: stackoverflow.com/help/how-to-ask Commented May 3, 2016 at 20:30

2 Answers 2

2

So now you got the metadata xml of the component, the Tridion core service role is over; it's all about compiling the xml and get the desired things out of it using .net.

So assuming you want to get the values of metadata fields, you can follow the below example code, I haven't run it though so you may need some adjustments as well.

doc = XDocument.Parse(component.Metadata);
xmlData = doc.Root;
var elements= xmlData.Descendants();
 foreach (XElement element in elements)
 { 
   //get the value using element.Value
 }
0

There are many core service code examples available in the Tridion Practice Cookbook. You can browse through them here: https://github.com/TridionPractice/tridion-practice?files=1

There are also many online blogs and q&a here with code samples too. Have a browse through, and if you still are stuck, let us know what exactly it is you're stuck on and we'd be happy to help.

1
  • thanks for the help. I got some progress and getting component data correctly but metadata fields are coming as below.. <Metadata xmlns=\"23232322323232\"> <a>Text-A</a> <a>Text-A</a> <c>Text-C</c> <d>Text-D</d> <e>Text-E</e> <e>Text-E</e> <g>Text-G</g> <h>Text-H</h> <i>Text-i</i> <j>1999-02-01</j> <k>2015-07-30</k> </Metadata> few elements are duplicate (e.g. <a>) in this. not sure how to get these values. I got the metadata values by XElement xMetaData = XElement.Parse(component.Metadata); I need to put the values in proper format.
    – San
    Commented May 4, 2016 at 18:59

Your Answer

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

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