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
| < | May 2012 | |||||
|---|---|---|---|---|---|---|
| S | M | T | W | T | F | S |
| 29 | 30 | 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 | 30 | 31 | 1 | 2 |
Add-ins AJAX ASP.NET MVC Browsers C# Caching CodeDom Compression CORS CSS CV Data Database DependencyResolver Development Dynamic Entity Framework Error Handling Extend 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 Templates Tools Twitter User Interface WCF Web Development WHS WMC XLinq XML
1 hours ago
TheNextWeb
Bing's search API now live on the Windows Azure Marketplace http://t.co/utX8uOuG by @alex
15/05/2012
WindowsAzure
Announcing the MEET Windows Azure Event! Streamed online June 7th. Register at http://t.co/bObzTAuL #MEETAzure #WindowsAzure
One hour ago
commadelimited
Buy the @amazon Kindle version of mine and @cfjedimaster's @jquerymobile book for $10 today: http://t.co/PWRZ2dkd
just now
CSSDropDownMenu
Simple horizontal css drop down menu demo Windows Azure and Cloud Computing Posts for 4/16/2011+ This makes fo... http://t.co/DZdNLHxF
just now
WAPForums
UpdateMessage() method not available in SDK 1.6? http://t.co/fyORSB1T Windows #Azure