我想使用核心服务为组件元数据设置多媒体链接。
我正在尝试如下,我得到xml验证错误。你能帮忙吗?
ComponentData comp = client.Read(compid, readoption) as ComponentData;
comp = client.TryCheckOut(compid, readoption) as ComponentData;
string newxml = @"<Metadata xmlns=""uuid:5880d67f-13f7-4632-8c33-dcfd9c1437ed"">
<meta>
<mmlink>tcm:22-5678</mmlink>
</metad>
</Metadata>";
comp.Metadata = newxml;
client.Save(comp, readoption);
client.CheckIn(comp.Id, readoption);
答案 0 :(得分:7)
您应该像{}一样设置xlink:href
:
<mmlink xlink:type="simple" xlink:href="tcm:2-146"
xmlns:xlink="http://www.w3.org/1999/xlink"></mmlink>
解决此类问题的最简单方法是使用相关字段和相应组件创建组件架构。然后,您将通过探索组件XML
找到答案答案 1 :(得分:3)
多媒体链接的方法与组件链接相同。它也适用于内容和元数据字段:此示例在文件夹元数据中设置mm组件链接,其中md模式构成一个名为“versioned_component”的可嵌入字段,其中包含一个名为“component”的字段,该字段是一个多媒体组件链接字段:
this.OpenSession();
try
{
//itemUri is the MM Component uri
var currentItem = (ComponentData)session.Read(itemUri, new ReadOptions());
LinkToRepositoryData ltrd = currentItem.LocationInfo.ContextRepository;
var pd = (PublicationData)session.Read(ltrd.IdRef, new ReadOptions());
String currentPublicationWebdavURL = pd.LocationInfo.WebDavUrl;
String schemaUri = string.Format(FOLDER_MD_SCHEMA_WEBDAVURL,
HttpUtility.UrlDecode(currentPublicationWebdavURL));
//schemaUri = HttpUtility.UrlEncode(schemaUri);
var sd = (SchemaData)session.Read(schemaUri, new ReadOptions());
FolderData folder = new FolderData();
folder.Id = TcmUri.UriNull;
folder.Title = "hidden_" + Guid.NewGuid().ToString();
var rootFolder = (FolderData)session.Read(
currentItem.LocationInfo.OrganizationalItem.IdRef,
new ReadOptions());
folder.LocationInfo= new LocationInfo()
{
OrganizationalItem = new LinkToOrganizationalItemData(){
IdRef = rootFolder.Id
}
};
folder.MetadataSchema = new LinkToSchemaData()
{
IdRef = sd.Id,
};
string sMetadata = "<Metadata xmlns=\"{0}\" xmlns:xlink=\"{1}\"> "
+ " <version_component>"
+ " <component xlink:type=\"simple\" "
+ " xlink:href=\"{2}\" xlink:title=\"{3}\" />"
+ " </version_component> "
+ "</Metadata>";
sMetadata = string.Format(sMetadata, sd.NamespaceUri,
Tridion.Constants.XlinkNamespace,
currentItem.Id.ToString(), currentItem.Title);
folder.Metadata = sMetadata;
folderUri = session.Save(folder, new ReadOptions()).Id.ToString();
return folderUri;
}
finally {
this.CloseSession();
}
希望这也有帮助,