In theory you can extend LinkUrl
class and pass the xml instead of the LinkField
object like that:
using System.Xml;
using Sitecore.Data;
using Sitecore.Xml.Xsl;
namespace My.Assembly.Namespace
{
public class ExtendedLinkUrl : LinkUrl
{
public string GetUrl(string linkFieldXml, Database database)
{
if (string.IsNullOrEmpty(linkFieldXml) || database == null)
return null;
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml(linkFieldXml);
var linkElement = xmlDocument.DocumentElement;
if (linkElement == null)
return null;
string linkType = linkElement.GetAttribute("linktype");
string url = linkElement.GetAttribute("url");
string id = linkElement.GetAttribute("id");
string anchor = linkElement.GetAttribute("anchor");
string queryString = linkElement.GetAttribute("querystring");
if (!string.IsNullOrEmpty(anchor))
anchor = "#" + anchor;
switch (linkType)
{
case "anchor":
return anchor;
case "external":
return GetExternalUrl(url);
case "internal":
return GetInternalUrl(database, url, id, anchor, queryString);
case "javascript":
return GetJavaScriptUrl(url);
case "mailto":
return GetMailToLink(url);
case "media":
return GetMediaUrl(database, id);
default:
return string.Empty;
}
}
}
}