Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 358857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:20:21+00:00 2026-05-12T12:20:21+00:00

I am querying an HTML file with LINQ-to-XML. It looks something like this: <html>

  • 0

I am querying an HTML file with LINQ-to-XML. It looks something like this:

<html>
    <body>
        <div class="Players">
        <div class="role">Goalies</div>
        <div class="name">John Smith</div>
        <div class="name">Shawn Xie</div>
        <div class="role">Right Wings</div>
        <div class="name">Jack Davis</div>
        <div class="name">Carl Yuns</div>
        <div class="name">Wayne Gortonia</div>
        <div class="role">Centers</div>
        <div class="name">Lutz Gaspy</div>
        <div class="name">John Jacobs</div>
        </div>
    </body>
</html>

What I’m trying to do is create a list of these folks like in a list of a structure called Players:

Structure Players
    Public Name As String
    Public Position As String
End Structure

But I’ve quickly found out I don’t really know what I’m doing when it comes to LINQ.

I’ve got this far in my queries:

Dim goalieList = From d In player.Elements _
                 Where d.Value = "Goalies" _
                 Select From g In d.ElementsAfterSelf _
                 Take While (g.@class <> "role") _
                 Select New Players With {.Position = "Goalie", _
                         .Name = g.Value}

Dim centersList = From d In player.Elements _
                  Where d.Value = "Centers" _
                  Select From g In d.ElementsAfterSelf _
                  Take While (g.@class <> "role") _
                  Select New Players With {.Position = "Centers", _
                         .Name = g.Value}

Which gets me down to the players by position, but then I can’t do much with this afterwards the result type is System.Collections.Generic.IEnumerable(Of System.Collections.Generic.IEnumerable(Of Player))

What I want to do is add these two results to a new list, like:

Dim playersList As List(Of Players) = Nothing
playersList.AddRange(centersList)
playersList.AddRange(goalieList)

So that I can then query the list and use it. But it kicks the error:

Unable to cast object of type
‘WhereSelectEnumerableIterator2[System.Xml.Linq.XElement,System.Collections.Generic.IEnumerable1[Players]]’
to type
‘System.Collections.Generic.IEnumerable`1[Players]’

As you can see, I may really have no idea how to work with all these objects/classes. Does anyone have any insight on what I may be doing wrong and how I can resolve it?

RESOLVED: The LINQ query needs to return a single IEnumerable, like this:

Dim goalieList = From l In _
                    (From d In players.Elements _
                     Where d.Value = "Goalies" _
                     Select d.ElementsAfterSelf.TakeWhile(Function(f) f.@class <> "role")) _
                  Select New Players With {.Position = "Goalie", .Name = l.Value}

and then use goalieList.ToList

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T12:20:21+00:00Added an answer on May 12, 2026 at 12:20 pm

    I fail at VB, but in C# you would call ToList() on the centersList and goalieList.

    So something like:

    playersList.AddRange(centersList.ToList())
    playersList.AddRange(goalieList.ToList())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.