Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I embed XElements into XML literals in VB.NET?

In VB.NET I can easily embed strings into XML literals using <xml><%= "my string" %></xml>.

How can I embed an XElement instance?

I know I can use methods on the XElement, XNode, etc classes, but I'd like to do it in the XML literals if possible.

like image 330
John Mills Avatar asked Jul 26 '10 14:07

John Mills


1 Answers

It turns I can simply do the following:

Function GetSomeMoreXml() As XElement
   Return <moreXml/>
End Function

Sub Main()
   Dim myXml = <myXml>
                  <%= GetSomeMoreXml() %>
               </myXml>
End Sub

Which is pretty neat. It allows me to break up my XML literals into more manageable chunks.

like image 96
John Mills Avatar answered Oct 09 '22 00:10

John Mills