tags:

views:

462

answers:

1

As basic as this is, it took me a few minutes to figure out, so wanted to share with the rest of the community to avoid anyone else from wasting their time.

I am attempting to generate the following XML string using VB.NET XML Literals

<Books>
    <Book Name="The First Book" />
    <Book Name="The Second Book" />
</Books>

I wrote the code like this (Assume Books is just an Enumerable of String),

Dim output = <Books>
    <%= From book In Books _
    Select _
    <Book Name="<%= book %>"/> %>
    </Books>

But the compiler is complaining about the quotes that are supposed to surround the attribute value. I tried using single quotes, two double quotes, nothing works.

A: 

After some quick experimentation, I figured out that you need to remove the quotes altogether, so the code looks like:

Dim output = <Books>
    <%= From book In Books _
    Select _
    <Book Name=<%= book %>/> %>
    </Books>
Justin Largey