Unable to display Xml SiteMap on CKEditor



Xml.cshtml



@Html.TextArea("", ViewData.TemplateInfo.FormattedModelValue.ToString())
<script type="text/javascript">
CKEDITOR.replace('@(ViewData.TemplateInfo.HtmlFieldPrefix)', {
allowedContent: true
});
</script>


ViewModel



public class MyViewModel
{
public int Id { get; set; }
[UIHint("Xml")]
public string Xml { get; set; }
}


View



@model Project1.ViewModels.MyViewModel
@Html.EditorFor(model=>model.Xml)


Controller



public ActionResult MyAction()
{
var sitemap = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement(ns + "urlset",
new XElement(ns + "url",
new XElement(ns + "loc", "example.com"),
new XElement(ns + "lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now)),
new XElement(ns + "changefreq", "Weekly"),
new XElement(ns + "priority", "0.5")
)));
var viewModel = new MyViewModel();
viewModel.Id = 5;
viewModel.Xml = sitemap.ToString();
return View(viewModel);
}


Inside the controller, site map was created and the viewmodel, which holds the Xml, sent to the View. In the View, EditorFor was converted to CKEditor successfully. But the problem is that it removes the Xml tags and displays plain text. If I display the source, Xml can be seen properly. I just installed the CodeSnippet plugin and add config.extraPlugins = 'codesnippet'; to the config.js but didn't make any difference. How can I display the sitemap as Xml in the CKEditor?


No comments:

Post a Comment