Reputation: 10919
A while back, I asked this question:
Does VB.NET have a multi-line string declaration syntax equivalent to c#?
Here I was introduced to XML literals in VB.NET. Using this syntax, I was able to simulate the multi-line string syntax available in c# using the @
symbol. However, I've come upon a snag. It seems that putting <
or >
in the text does not sit well in the belly of Visual Studio. Take this code as an example:
Dim Sql As String = <a><![CDATA[]]>
<text instead pointy brackets fails>
</a>.Value
Can I somehow escape these brackets or tell the literal not to care about it?
Upvotes: 0
Views: 1909
Reputation: 181
You need to put the text within the CDATA section:
Dim Sql As String = <a><![CDATA[
<text instead pointy brackets fails>
]]></a>.Value
Console.WriteLine("===")
Console.WriteLine(Sql)
Console.WriteLine("===")
should output:
===
<text instead pointy brackets fails>
===
Note that CDATA will also preserve leading spaces in your text; that is why I removed them from the bracketed text.
Upvotes: 2
Reputation: 1500675
XML literals are only for XML data. You could use <
to escape the left angle brackets, but really unless you genuinely want XML data I would suggest you don't use XML literals at all.
Upvotes: 4