Login

How do I save a page as XHTML?

Versions: 4.70, FAQ number: 98, Old FAQ number: 942

Q: How do I save a page as XHTML?

A: By default EPiServer saves pages exactly the way they are posted by the browser. This is by design. However, if you want the page to be saved as XHTML for instance, you can do so. Capture the PageSaving event and convert the HTML to XHTML using EPiServer's built-in HTML parser. See sample below.

Add the following to Global.asax.cs:

using EPiServer.Core.Html;
using EPiServer.Core;

protected void Application_Start(Object sender, EventArgs e)
{
 Global.EPDataFactory.SavingPage +=
    new EPiServer.PageEventHandler(EPDataFactory_SavingPage);
}

private void EPDataFactory_SavingPage(
               Object sender, EPiServer.PageEventArgs e)
{   
 if (e.Page["MainBody"] != null)
 {
   HtmlParser parser = new HtmlParser(e.Page["MainBody"].ToString());   
   e.Page["MainBody"] = parser.ToString();
 }
}

Note: the EPiServer HTML to XHTML converter parses HTML using a DTD that is based on W3C's loose.dtd (complete name "http://www.w3.org/TR/html4/loose.dtd").

EPiTrace logger