{"id":853,"date":"2010-05-24T17:04:40","date_gmt":"2010-05-24T17:04:40","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vbteam\/2010\/05\/24\/using-html-entities-in-xml-literals-avner-aharoni\/"},"modified":"2024-07-05T12:41:15","modified_gmt":"2024-07-05T19:41:15","slug":"using-html-entities-in-xml-literals-avner-aharoni","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/vbteam\/using-html-entities-in-xml-literals-avner-aharoni\/","title":{"rendered":"Using HTML entities in XML Literals (Avner Aharoni)"},"content":{"rendered":"<p>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 <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.xml.linq.xdocumenttype.aspx\">here<\/a>. <\/p>\n<p>The workaround is to use the Unicode representation of the entity, although it\u2019s not as readable as the HTML entities, the output is the same. <\/p>\n<p>Here are two examples of HTML entities from the <a href=\"http:\/\/www.w3.org\/TR\/xhtml1\/dtds.html#a_dtd_Latin-1_characters\">XHTML spec<\/a> :     <\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"121\">\n<p><b>&#160; Entity<\/b><\/p>\n<\/td>\n<td valign=\"top\" width=\"114\">\n<p><b>&#160; Unicode<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"121\">\n<p>&#160; &amp;nbsp;<\/p>\n<\/td>\n<td valign=\"top\" width=\"114\">\n<p>&#160; &#160;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"121\">\n<p>&#160; &amp;copy;<\/p>\n<\/td>\n<td valign=\"top\" width=\"114\">\n<p>&#160; &#169;<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>And here is a small test program to show you can substitute the HTML entity with the Unicode representation:<\/p>\n<pre>&#160; Dim html = &lt;p&gt;My&#160;Name&#160;Is&#160;Avner, &#169; 2010 Microsoft &lt;\/p&gt;<br \/>&#160;&#160; html.Save(&quot;test.html&quot;)<br \/>&#160;&#160; Process.Start(&quot;test.html&quot;)<\/pre>\n<p>The output looks like this:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/7\/2019\/02\/clip_image002_2.jpg\"><img decoding=\"async\" style=\"border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px\" title=\"clip_image002\" border=\"0\" alt=\"clip_image002\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2010\/05\/clip_image002_thumb.jpg\" width=\"338\" height=\"78\" \/><\/a><\/p>\n<div class=\"wlWriterHeaderFooter\" style=\"margin:0px;padding:0px 0px 0px 0px\">\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":260,"featured_media":8818,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[195],"tags":[38,94,166,185],"class_list":["post-853","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-visual-basic","tag-avner-aharoni","tag-linqvb9","tag-vb2008","tag-xml"],"acf":[],"blog_post_summary":"<p>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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/853","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/users\/260"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/comments?post=853"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/853\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media\/8818"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media?parent=853"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/categories?post=853"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/tags?post=853"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}