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

Related Questions

I am using an XMLTextReader to process an XML file (as opposed to an
I'm attempting to read the content of a XML file, using XmlTextReader in C#,
I have an XML document and I am using XmlTextReader of System.Xml namespace to
I have xml file with TAG like this: <Question>dzia&amp;#322;owa</Question> I'm reading this file using
I am parsing some xml entries using the xmltextreader and looking for the elements
I am trying reading in data from XML files using C# XMLTextReader. Most of
Using C#, I need a class called User that has a username, password, active
I wondering about sense of using XmlDocument class to processing a small XML files.
Using online interfaces to a version control system is a nice way to have
Using PyObjC , you can use Python to write Cocoa applications for OS X.

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.