Using HTML entities in XML Literals (Avner Aharoni)

Using HTML entities in XML Literals (Avner Aharoni)

  • Comments 2

One of the common use-cases of XML literals is creating HTML. However, HTML entities cannot be used in XML literals since LINQ to XML directly supports only the Data type definitions (DTD) defined in the XML 1.0 spec. You can read more about it here.

The workaround is to use the Unicode representation of the entity, although it’s not as readable as the HTML entities, the output is the same.

Here are two examples of HTML entities from the XHTML spec :

  Entity

  Unicode

   

   

  ©

  ©

And here is a small test program to show you can substitute the HTML entity with the Unicode representation:

  Dim html = <p>My&#160;Name&#160;Is&#160;Avner, &#169; 2010 Microsoft </p>
   html.Save("test.html")
   Process.Start("test.html")

The output looks like this:

clip_image002



Leave a Comment
  • Please add 4 and 5 and type the answer here:
  • Post
  • There is no doubt that VB10 beats it's C# competitor badly.

    Thanks for posting

    כחול לבן

  • thanks...

Page 1 of 1 (2 items)