XML output from Template has whitespace at the beginning...
I am trying to create an RSS feed of my news site by creating a document (simple document type used elsewhere) but with a different template. The template is as follows:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = "";
umbraco.library.ChangeContentType("text/xml");
Html.RenderPartial("parNewsRSS");
}
The Partial View start like...
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
var home = UmbracoContext.ContentCache.GetAtRoot().Single(x => x.DocumentTypeAlias == "Home");
var newsOverview = home.Children.Single(x => x.DocumentTypeAlias == "NewsOverview");
var newsItems = newsOverview.Children.Where(x => x.DocumentTypeAlias == "NewsItem")
So I took the XML processing Instruction out of the Partial View and placed it right at the top of the Template. I also removed the inherts statement from the Template.
XML output from Template has whitespace at the beginning...
I am trying to create an RSS feed of my news site by creating a document (simple document type used elsewhere) but with a different template. The template is as follows:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = "";
umbraco.library.ChangeContentType("text/xml");
Html.RenderPartial("parNewsRSS");
}
The Partial View start like...
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
var home = UmbracoContext.ContentCache.GetAtRoot().Single(x => x.DocumentTypeAlias == "Home");
var newsOverview = home.Children.Single(x => x.DocumentTypeAlias == "NewsOverview");
var newsItems = newsOverview.Children.Where(x => x.DocumentTypeAlias == "NewsItem")
.ToList().OrderBy("publishDate desc, createDate desc");
DateTime latestDateTime = newsItems.First().GetPropertyValue<DateTime>("publishDate", newsItems.First().CreateDate);
var siteUrl = "http://" + Request.Url.Host;
}
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
version="2.0">
<channel>
However when it is rendered, I am getting a whitespace line before the <?xml instruction.
Any chance I am going about this the wrong way or is there a standard way to trim out this type of whitespace ?
I am using Umbraco 7.1.4 with Razor engine.
Thanks
Russell
Managed to get things working using the following:
The template is as follows:
<?xml version="1.0" encoding="UTF-8"?>
@{
Layout = "";
umbraco.library.ChangeContentType("text/xml");
Html.RenderPartial("parNewsRSS");
}
The Partial View start like...
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
var home = UmbracoContext.ContentCache.GetAtRoot().Single(x => x.DocumentTypeAlias == "Home");
var newsOverview = home.Children.Single(x => x.DocumentTypeAlias == "NewsOverview");
var newsItems = newsOverview.Children.Where(x => x.DocumentTypeAlias == "NewsItem")
.ToList().OrderBy("publishDate desc, createDate desc");
DateTime latestDateTime = newsItems.First().GetPropertyValue<DateTime>("publishDate", newsItems.First().CreateDate);
var siteUrl = "http://" + Request.Url.Host;
}
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
version="2.0">
<channel>
So I took the XML processing Instruction out of the Partial View and placed it right at the top of the Template. I also removed the inherts statement from the Template.
is working on a reply...