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

  • SEARCH
  • Home
  • 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 799883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:12:12+00:00 2026-05-14T23:12:12+00:00

I am trying to wrap my brain around using LINQ as a means of

  • 0

I am trying to wrap my brain around using LINQ as a means of working with XML data and I’m having a problem figuring out the best way to select elements into a strongly-typed collection. I’m sure there’s some minute detail I’m missing, but I can’t seem to see it.

Here is a sample of my XML File:

    <users>
      <User>
        <UserId>a3ba555e-9dbe-4f5e-a8b0-56be91a99eae</UserId>
        <Password>FCC2427123934BC2A06297847574A50E</Password>
        <Username>TestTEst</Username>
        <FirstName>Test</FirstName>
        <LastName>TestTEst</LastName>
      </User>
      <User>
        <UserId>500629d5-c22a-4585-bc85-330391f44fac</UserId>
        <Password>FCC2427123934BC2A06297847574A50E</Password>
        <Username>TestTEst</Username>
        <FirstName>Test</FirstName>
        <LastName>TestTEst</LastName>
      </User>
      <User>
        <UserId>bd6b78db-9cd7-403b-a757-a8c013bdc523</UserId>
        <Password>FCC2427123934BC2A06297847574A50E</Password>
        <Username>TestTEst</Username>
        <FirstName>Test</FirstName>
        <LastName>TestTEst</LastName>
      </User>
</users>

When I create an object using the following code:

Dim userList = From u In users.Descendants("user") _
               Select u

Then userList will contain the elements of my XML file. If I try to select the XML file into a strongly-typed collection instead:

Dim userList = (From u In users.Descendants("user") _
               Select New User With { _
                   .UserId = New Guid(u.Attribute("UserId").Value), _
                   .Username = u.Attribute("Username").Value, _
                   .Password = u.Attribute("Password").Value, _
                   .FirstName = u.Attribute("FirstName").Value, _
                   .LastName = u.Attribute("LastName").Value _
               }).ToList()

Then userList is empty. This is the same whether or not I explicitly specify the type of userList (List(Of User)). What am I doing wrong? What is the correct way to create a strongly-typed collection directly from XML?

Thanks,

Mike

  • 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-14T23:12:13+00:00Added an answer on May 14, 2026 at 11:12 pm

    I think your problem here is that “UserID”, “Username”, “Password”, etc. are not attributes of the User tag, they are sub-elements. Might want to try this:

    Dim userList = (From u In users.Descendants("user") _
                   Select New User With { _
                       .UserId = New Guid(u.Decendants("UserId").First().Value), _
                       .Username = u.Decendants("Username").First().Value, _
                       .Password = u.Decendants("Password").First().Value, _
                       .FirstName = u.Decendants("FirstName").First().Value, _
                       .LastName = u.Decendants("LastName").First().Value _
                   }).ToList()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am still trying to wrap my brain around this whole xml serialization thing,
Just trying to wrap my brain around open source cloud. 1) Is OpenStack running
I am trying wrap my head around how data is being served to Project
I'm trying to wrap my head around a particular subtlety of using asynchronous script
I'm trying to wrap my brain around JMS and have been reading up on
I'm teaching myself XSLT and am still trying to wrap my brain around the
Trying to wrap my brain around animations here. Here is my basic situation: _________
So, newbie NHibernate user; trying to wrap my brain around it. I'm contemplating how
I'm trying to wrap my brain around a query and hoping you can help.
I am trying to wrap my brain around Rack::Cache, Rails 3.2, Memcache, and Heroku.

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.