Understanding Embedded Expressions

With embedded expressions, you can include local variables or perform dynamic queries within XML literals. Let’s look again at the first example about XML literals, where an XML document contains a couple of contacts. Imagine you want to generate a contact starting from some variables (that you could populate at runtime with different values) instead of hard-coding the last name, first name, and age. This can be accomplished as follows:

'All with type inferenceDim FirstName = "Alessandro"Dim LastName = "Del Sole"Dim Age = 37Dim Contacts = <?xml version="1.0"?>            <Contacts>                <Contact LastName=<%= LastName %>                    FirstName=<%= FirstName %>                    Age=<%= ...

Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.