Example using metadata fields (.NET)
Metadata fields specify properties for a Page, Structure Group, Folder or Publication. If metadata is added to these items using a Metadata Schema, you can then use the values in these fields during processing.
You can use metadata values in the following types of scenarios:
- Localization
- Archiving
- Folder ownership
- Directing publishing processes
- Automatic publishing
For example, if you have a metadata field for a Structure Group to specify the color scheme of Pages contained in that Structure Group. To retrieve this information from the Structure Group metadata, use the Metadata property.
static void UsingMetadataFields(CoreServiceClient client)
{
const string structureGroupUri = "tcm:2-3-4";
StructureGroupData structureGroup = (StructureGroupData)client.Read(structureGroupUri, null);
// Load metadata in a XDocument
XDocument doc = XDocument.Parse(structureGroup.Metadata);
// figure out metadata namespace
XNamespace ns = doc.Root.Attribute("xmlns").Value;
// check for a field called ColorScheme
XElement colorScheme = doc.Root.Element(ns + "ColorScheme");
if (colorScheme != null)
{
Console.WriteLine("ColorScheme = {0}", colorScheme.Value);
}
else
{
Console.WriteLine("No color scheme specified");
}
}