Archive

Posts Tagged ‘XElement’

Dynamicaly create XML Elements in XML Literals

February 6, 2011 Leave a comment

XML Literals

d is a Class that has a Fuction named GetXMLFilenames defined.
GetXMLFilenames returns a List(Of XElements).


Dim _XMLDoc = <OBJECT>
  <OBJTYPE>0</OBJTYPE>
  <PAGES><%= d.PageCount %></PAGES>
  <%= From elem In d.GetXMLFilenames Select
     New XElement(elem.Name, elem.Value)
  %>
</OBJECT>
  
   Public Function GetXMLFilenames() As List(Of XElement)
      Try
         Dim tempstr As String = ""
         Dim _XElementList As New List(Of XElement)

         Dim _i As Integer = 0
         For Each _Filename In _Filenames
            _i += 1
            Dim _XElement As New XElement("FILE" &amp; _i, _Filename)
            _XElementList.Add(_XElement)
         Next
         Return _XElementList

      Catch ex As Exception
         Throw ex
      End Try
   End Function

Categories: LINQ, VB.NET Tags: