O'Reilly logo

Microsoft® Visual Basic® 2010 Developer’s Handbook by Klaus Löffelmann and Sarika Calla Purohit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

XML Literals: Using XML Directly in Code

It gets even better. Again, beginning with Visual Basic 2008, you can create documents that work with XDocument and XElement objects directly in code. These inline XML documents are called XML literals. The following example shows how this works:

Dim fleet As XElement = <fleet>
                                    <licensePlate>MS - VB 2010</licensePlate>
                                    <load amount="10 Tons">Salt</load>
                                    <manufacturer>Mack</manufacturer>
                                </fleet>

The fleet object is a simple Xelement. You can add the modelYear element as usual:

fleet.Add(New XElement("modelYear", 1998))

And it’s even easier with XML literals:

fleet.Add(<modelYear>1998</modelYear>)

Including Expressions in XML Literals

Inline XML documents don’t need to be completely static; they can include dynamic ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required