3

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.

1 Answer 1

4

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.