Can i embed LINQ results into CDATA?
Can i merge the values returned from a LINQ query (in the next example c.day) with CDATA like...
Dim Result = <items>
<%= From c In db.News 开发者_JAVA技巧Select _
<item>
<day><![CDATA[<font size="30" color="#7CBEBD"><%= c.day %></font>]]></day>
</item> %>
</items>
I don't think you can use CDATA section literals and embedded expressions inside them with VB.NET but you can certainly construct a CDATA section node with new XCData()
as in the following example:
Dim words As String() = {"foo", "bar", "baz"}
Dim doc As XDocument =
<?xml version="1.0"?>
<root>
<items>
<%= From word In words
Select <item>
<%= New XCData("<font size=""3"">" + word + "</font>") %>
</item>
%>
</items>
</root>
That serializes as
<root>
<items>
<item><![CDATA[<font size="3">foo</font>]]></item>
<item><![CDATA[<font size="3">bar</font>]]></item>
<item><![CDATA[<font size="3">baz</font>]]></item>
</items>
</root>
精彩评论