2

I am experimenting with using VB.Net's Xml Literals as a templating system for generating HTML. What I am wondering if there is any way to control the escaping. For example if I have code similar to the following

Dim param1Value as String = "test"
Dim html = <div>
               <a id="myLink" href="<%= "/mysite/myfile?param1=" + param1Value + "&param2=test2" %>"
           </div>

This will produce a link with the ampersands xml encoded (&amp;). Currently, I am just un-escaping these when transforming the xmlElement to a string. I am assuming that is my only option as anything else produces invalid XML, but I was wondering if there was any way to specify that an XML Literal is a raw value and does not need Xml Escaped.

4

1 回答 1

1

Years ago, I created an ASP.NET MVC View Engine using VB.NET XML Literals in which I had to solve this exact problem. There was no way to tell the Xml literals part of vb.net to ignore & characters. My particular scenario was trying to include HTML entities (like &copy;) within the Xml literals.

What I ended up with was using <amp /> in all the places where I needed the & character within an XML Literal and then just doing a .Replace("<amp />", "&") when rendering the HTML. See the Render method in VbView.vb.

于 2015-03-24T22:36:40.383 回答