Does XHTML5 support character entities such as
and —
. At work we can require specific software to access the admin side of the
Using the following answer: https://stackoverflow.com/a/9003931/689044 , I created the file and posted it as a Gist on GitHub: https://gist.github.com/cerkit/c2814d677854308cef57 for those of you who need the Entities in a file.
I used it successfully with ASP.NET MVC by loading the text file into the Application object and using that value with my (well-formed) HTML to parse a System.Xml.XmlDocument.
XmlDocument doc = new XmlDocument();
// load the HTML entities into the document and add a root element so it will load
// The HTML entities are required or it won't load the document if it uses any entities (ex: –)
doc.LoadXml(string.Format("{0}{1} ", Globals.HTML_ENTITIES, control.HtmlText));
var childNodes = doc.SelectSingleNode("//root").ChildNodes;
// do your work here
foreach(XmlNode node in childNodes)
{
// or here
}
Globals.HTML_ENTITIES is a static property that loads the entities from the text file and stores them in the Application object, or it uses the values if they're already loaded in the Application object.
public static class Globals
{
public static readonly string APPLICATION_KEY_HTML_ENTITIES = "HTML_ENTITIES";
public static string HTML_ENTITIES
{
get
{
string retVal = null;
// load the HTML entities from a text file if they're not in the Application object
if(HttpContext.Current.Application[APPLICATION_KEY_HTML_ENTITIES] != null)
{
retVal = HttpContext.Current.Application[APPLICATION_KEY_HTML_ENTITIES].ToString();
}
else
{
using (StreamReader sr = File.OpenText(HttpContext.Current.Server.MapPath("~/Content/HtmlEntities/RootHtmlEntities.txt")))
{
retVal = sr.ReadToEnd();
HttpContext.Current.Application[APPLICATION_KEY_HTML_ENTITIES] = retVal;
}
}
return retVal;
}
}
}
I tried creating a long string to hold the values, but it kept crashing Visual Studio, so I decided that the best route would be to load the text file at runtime and store it in the Application object.