Consider the following code in VB9:
Dim text = 'Line1<br/>Line2' Dim markup = <span><%= text %></span>.ToString
While I was hoping markup would end up being <span>Line1<br/>Line2</span>, it actually evaluates to <span>Line1<br/>Line2</span>.
Is there any way to get the value of the variable not to be HTML encoded?
P.S.: This is an oversimplified example of what I’m trying to do. I know this could be rewritten a number of ways to make it work, but the way my code is constructed, un-encoding the variable would be optimal. If that’s not possible, then I’ll go down a different road.
More detail: The ‘text’ is coming from a database, where a user can enter free-form text, with carriage returns. The output is HTML, so somehow I need to get the value from the database and convert the carriage returns to line breaks.
This behavior is ‘By Design.’ When embedding a string expression inside an XML literal the value will be escaped to be a legal string value.
To get the behavior you are looking for you’ll need to be embedding an XElement/XNode within an XML literal. Take the following example. It will correctly keep the
<br/>tag as an XElement.One way to achieve this is to fake an XElement. To make the text a valid string, simply wrap it on both ends with a normal tag,
<a>for example. This is now a parsable XML fragment. Once you have an XElement, it’s easy to get the embedded behavior you are looking for