This lets you create and add dynamic content to
your XML literal.
In the following example, a standard LINQ query is embedded in the XML literal, which will create an
XML tree based on the value returned from the query.
Dim emp As XElement = _
<%= From con in Contact
Select <%= con.FirstName %>
%>
That gives you an idea of what is possible when LINQ queries are embedded in XML literals. However,
take it a step further and add an attribute to the XML. Modify the XML as highlighted:
Dim emp As XElement = _
<%= From con in Contact
Select ><%= con.FirstName %>
%>
Now you have a good understanding of how easy it is to dynamically create and add content
to your XML.
Understanding Whitespace in Visual Basic XML Literals
Only significant whitespace is included in an XML literal by the Visual Basic compiler when a LINQ to
XML object is created. Any insignificant whitespace is ignored.
To illustrate how whitespace is used, add the following code to the click event of one of the buttons
on your form:
Dim empID As String
Dim empName As String
empID = "ID"
empName = "FirstName"
Dim emp As XElement = _
184
Chapter 9: LINQ to XML and Visual Basic .
Pages:
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313