I thought XLinq would be a convenient way to load and manipulate XHTML data but was scuppered as it wouldn't parse due to some undeclared entities for example.
In order to load/parse an XHTML document using XLinq you must do two things.
/// <summary>
/// <para>XmlResolver for XHTML</para>
/// </summary>
public class XhtmlResolver : XmlUrlResolver {
/// <summary>
/// <para>URN string to identify all the Entities</para>
/// </summary>
private const string ENTITIES_URN = "urn:Entities";
/// <summary>
/// <para>Get Entity</para>
/// </summary>
public override object GetEntity(
Uri absoluteUri, string role,
Type ofObjectToReturn) {
if (absoluteUri.AbsoluteUri == ENTITIES_URN) {
return "<!ENTITY nbsp \" \" >";
}
return null;
}
/// <summary>
/// <para>Resolves XHTML DOCTYPE</para>
/// </summary>
public override Uri ResolveUri(
Uri baseUri, string relativeUri) {
// make sure the doc is declared as XHTML
if (relativeUri.Equals("-//W3C//DTD XHTML 1.0 Transitional//EN", StringComparison.OrdinalIgnoreCase)
|| relativeUri.Equals("-//W3C//DTD XHTML 1.0 Strict//EN", StringComparison.OrdinalIgnoreCase)
|| relativeUri.Equals("-//W3C//DTD XHTML 1.0 Frameset//EN", StringComparison.OrdinalIgnoreCase)
|| relativeUri.Equals("-//W3C//DTD XHTML 1.1//EN", StringComparison.OrdinalIgnoreCase)) {
return new Uri(ENTITIES_URN);
}
return base.ResolveUri(baseUri, relativeUri);
}
}This will take care to the entities, to take care of all of them, either list all the entities in the GetEntity method or create an embedded resource file with the contents of http://www.w3.org/2003/entities/2007/isonum.ent.
Now to find out if XLinq is a convenient way to play with XHTML or not ...
http://www.w3.org/2003/entities/2007/isonum.ent
http://www.martinwilley.com/net/code/xhtmldoc.html
| < | February 2012 | |||||
|---|---|---|---|---|---|---|
| S | M | T | W | T | F | S |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 1 | 2 | 3 |
Add-ins AJAX ASP.NET MVC Browsers C# Caching Compression CORS CSS CV Data Database DependencyResolver Development Entity Framework Error Handling File Upload Forms GDI+ HTML HTML Editor HTTP Interfaces JavaScript JQuery MCE MetadataProvider MSBuild Numbers Objects Patterns Progressive Enhancement Projects Publish Regex Resources Security SEO SMTP Source Control Strings Sub-Collections TDD Tools Twitter User Interface WCF Web Development WHS WMC XLinq XML
11 hours ago
verge
Microsoft teases Windows 8 'Consumer Preview' with Bing betta fish site http://t.co/lcJICazH