title: LINQ To XML Syntax and class objects in vb.net
body: <p>I have the following XML file</p>
  
  <pre><code>&lt;Test&gt;
    &lt;Modules&gt;
      &lt;Module Name= "Test1"&gt;
          &lt;QueueName Name="Test1Active1" Active="True"&gt;&lt;/QueueName&gt;
          &lt;QueueName Name="Test1Active2" Active="True"&gt;&lt;/QueueName&gt;
          &lt;QueueName Name="Test1Active3" Active="True"&gt;&lt;/QueueName&gt;
          &lt;QueueName Name="Test1Active4" Active="True"&gt;&lt;/QueueName&gt;
          &lt;QueueName Name="Test1Inactive1" Active="False"&gt;&lt;/QueueName&gt;
          &lt;QueueName Name="Test1Inactive2" Active="False"&gt;&lt;/QueueName&gt;
          &lt;QueueName Name="Test1Inactive3" Active="False"&gt;&lt;/QueueName&gt;
          &lt;QueueName Name="Test1Inactive4" Active="False"&gt;&lt;/QueueName&gt;
  
        &lt;OtherSettings TimePause="20" TimeElasped="25" NumberOfThreads="5"&gt;
  
          &lt;Connection tag="Test1Test1" Connection="TestCon1"&gt;&lt;/Connection&gt;
          &lt;Connection tag="Test1Test2" Connection="TestCon2"&gt;&lt;/Connection&gt;
          &lt;Url Tag="Test1Test1" Connection="TestUrl"&gt;&lt;/Url&gt;
          &lt;Url Tag="Test1Test2" Connection="TestUrl1"&gt;&lt;/Url&gt;
  
        &lt;/OtherSettings&gt; 
      &lt;/Module&gt;
      &lt;Module Name= "Test2"&gt;
  
          &lt;QueueName Name="Test2Active1" Active="True"&gt;&lt;/QueueName&gt;
          &lt;QueueName Name="Test2Active2" Active="True"&gt;&lt;/QueueName&gt;
          &lt;QueueName Name="Test2Active3" Active="True"&gt;&lt;/QueueName&gt;
          &lt;QueueName Name="Test2Active4" Active="True"&gt;&lt;/QueueName&gt;
          &lt;QueueName Name="Test2Inactive1" Active="False"&gt;&lt;/QueueName&gt;
          &lt;QueueName Name="Test2Inactive2" Active="False"&gt;&lt;/QueueName&gt;
          &lt;QueueName Name="Test2Inactive3" Active="False"&gt;&lt;/QueueName&gt;
          &lt;QueueName Name="Test2Inactive4" Active="False"&gt;&lt;/QueueName&gt;
  
  
        &lt;OtherSettings&gt;
           &lt;Connection Tag="Test2Test1" Connection="TestCon1"&gt;&lt;/Connection&gt;
           &lt;Connection Tag="Test2Test2" Connection="TestCon2"&gt;&lt;/Connection&gt;
           &lt;Url Tag="Test2Test1" Connection="TestUrl"&gt;&lt;/Url&gt;
           &lt;Url Tag="Test2Test2" Connection="TestUrl1"&gt;&lt;/Url&gt;
        &lt;/OtherSettings&gt;
     &lt;/Module&gt;
    &lt;/Modules&gt;
  &lt;/Test&gt;
  </code></pre>
  
  <p>I have tried to am trying to fill classes from this </p>
  
  <pre><code>Partial Public Class Modules
      Private _moduleName As String
      Private _queueName As IEnumerable(Of QueueName)
      Private _otherSetting As OtherSetting
  
      Public Sub New()
  
      End Sub
      &lt;DebuggerBrowsable(DebuggerBrowsableState.Never)&gt; _
      Public Property ModuleName() As String
          Get
              Return _moduleName
          End Get
          Set(ByVal value As String)
              _moduleName = value
          End Set
      End Property
      &lt;DebuggerBrowsable(DebuggerBrowsableState.Never)&gt; _
      Public Property QueueName() As IEnumerable(Of QueueName)
          Get
              Return _queueName
  
          End Get
          Set(ByVal value As IEnumerable(Of QueueName))
              _queueName = value
  
          End Set
      End Property
      &lt;DebuggerBrowsable(DebuggerBrowsableState.Never)&gt; _
      Public Property OtherSetting() As OtherSetting
          Get
              Return _otherSetting
  
          End Get
          Set(ByVal value As OtherSetting)
              _otherSetting = value
  
          End Set
      End Property
  
  End Class
  </code></pre>
  
  <p>These work</p>
  
  <pre><code>  Friend Function GetDataModules() As List(Of Modules)
          Dim xdoc As XDocument = OpenXml()
  
          Dim modules = (From q In xdoc...&lt;Modules&gt;.&lt;Module&gt; _
                      Select New Modules With { _
                      .ModuleName = q.@Name _
                      }).ToList
  
  
          Return modules
  
      End Function
      Friend Function GetDataQueueNames(ByVal ModuleName As String, ByVal isActive As Boolean) As List(Of QueueName)
          Dim xdoc As XDocument = OpenXml()
  
          Dim active = (From q In xdoc...&lt;Modules&gt;.&lt;Module&gt; _
                        Where q.@Name = ModuleName _
                        From l In q.&lt;QueueName&gt; _
                        Where Convert.ToBoolean(l.@Active) = isActive _
                        Select New QueueName With { _
                          .Name = l.@Name, _
                          .Active = Convert.ToBoolean(l.@Active) _
                          }).ToList
  
  
  
  
          Return active
      End Function
  </code></pre>
  
  <p>This does not</p>
  
  <pre><code>Protected Function GetAllData() As List(Of Modules)
  
      Dim xdoc As XDocument = OpenXml()
      Dim All = From m In xdoc...&lt;Module&gt;.&lt;Module&gt; _
           Select New Modules With { _
           .ModuleName = m.@Name _
           }, _
           .QueueName = From q In m...&lt;QueueName&gt; _
           Select New QueueName With { _
           .Name = q.@Name, _
           .Active = Convert.ToBoolean(q.@Active) _
           }, _
           .OtherSetting = From o In m...&lt;OtherSettings&gt; _
           Select New OtherSetting() With { _
           .TimeElasped = Convert.ToInt32(o.@TimeElasped), _
           .TimePause = Convert.ToInt32(o.@TimePause), _
           .NumberOfThreads = Convert.ToInt32(o.@NumberOfThreads) _
            }, _
           .Connection = From c In m...&lt;Connection&gt; _
           Select New Connection With { _
           .ConnectionString = c.@Connection, _
           .Tag = c.@Tag _
           }, _
          .URL = From u In m...&lt;Url&gt; _
          Select New URL() With { _
          .Tag = u.@Tag, _
          .URL = u.@Url _
         }.tolist
  End Function
  </code></pre>
  
  <p>Could you please help </p>