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 192199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:24:21+00:00 2026-05-11T16:24:21+00:00

using xmltextreader, how would I load a hashtable. XML: <base><user name=john>2342343</user><user name=mark>239099393</user></base> This was

  • 0

using xmltextreader, how would I load a hashtable.

XML:

<base><user name="john">2342343</user><user name="mark">239099393</user></base>

This was asked before but it was using some funky linq that I am not fully comfortable with just yet.

  • 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-11T16:24:21+00:00Added an answer on May 11, 2026 at 4:24 pm

    Well, the LINQ to XML solution is really easy, so I suggest we try to make you comfortable with that instead of creating a more complex solution. Here’s the code, with plenty of explanation…

    // Load the whole document into memory, as an element
    XElement root = XElement.Load(xmlReader);
    
    // Get a sequence of users
    IEnumerable<XElement> users = root.Elements("user");
    
    // Convert this sequence to a dictionary...
    Dictionary<string, string> userMap = users.ToDictionary(
          element => element.Attribute("name").Value, // Key selector
          element => element.Value);                 // Value selector
    

    Of course you could do this all in one go – and I’d probably combine the second and third statements. But that’s about as conceptually simple as it’s likely to get. It would become more complicated if you wanted to put error handling around the possibility that a user element might not have a name, admittedly. (This code will throw a NullReferenceException in that case.)

    Note that this assumes you want the name as the key and id as value. If you want the hashtable the other way round, just switch the order of the lambda expressions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 88k
  • Answers 88k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I consistently use Way 1: class Foo def self.bar puts… May 11, 2026 at 5:46 pm
  • Editorial Team
    Editorial Team added an answer #define test(name) testInSuite( name, TestSuite::active() ) However this doesn't reduce… May 11, 2026 at 5:46 pm
  • Editorial Team
    Editorial Team added an answer You can embed the image data directly into the page… May 11, 2026 at 5:46 pm

Related Questions

I am using an XMLTextReader to process an XML file (as opposed to an
I am running into the same problem as in this question: How do you
I'm loading data into a DataSet from an XML file using the ReadXml method.
I have SQL table that has a varchar(8) column that occasionally has binary data
I am trying to render some XAML at runtime. My XAML is dynamically constructed

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.