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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:43:22+00:00 2026-05-14T20:43:22+00:00

How to add data to dictonary from xml file scenerio: I’ve declared a dictonary

  • 0

How to add data to dictonary from xml file

scenerio:

I’ve declared a dictonary like

 Dictonary<string,string> SampleDict=new Dictonary<string,string>();

and my xml file is like

 <Data>
   <Element ValOne="1" ValTwo="0" />
   <Element ValOne="2" ValTwo="2" />
   <Element ValOne="3" ValTwo="4" />
   <Element ValOne="4" ValTwo="6" />
   <Element ValOne="5" ValTwo="8" />
   <Element ValOne="6" ValTwo="10" />
   <Element ValOne="7" ValTwo="12" />
   <Element ValOne="8" ValTwo="14" />
   <Element ValOne="9" ValTwo="16" />
   <Element ValOne="10" ValTwo="18" />
</Data>

i need to read the value of “ValOne” and “ValTwo” using LINQ and insert the same into the above declared dictonary

and how to add the contents of the dictonary to a listview which contains two columns.

Please help me to do this

Thanks in advance

  • 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-14T20:43:23+00:00Added an answer on May 14, 2026 at 8:43 pm

    You can use Linq to XML and ToDictionary for this.

    var doc = XDocument.Load("path to xml");
    doc.Elements("Element").ToDictionary(
      elem => elem.Attribute("ValOne").Value, //Dictionary key
      elem => elem.Attribute("ValTwo").Value  //Dictionary value
    );
    

    This particular overload of ToDictionary uses different lambdas to extract keys and values for the generated collection.

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

Sidebar

Related Questions

Things like $log$ and $version$ which add data upon check-in to the file. I'm
I've seen this quite a few times while using Office Interop classes this.CustomXMLParts.Add(MyResources.Data, new
I wrote a Java program to add and retrieve data from an MS Access.
I'm wondering if its possible to add new class data members at run-time in
I am trying to add data to a newly created column... DataSet ds =
I can make a DAO recordset in VB6/Access do anything - add data, clean
How do I add extra data into an atom feed that does not map
I have a table of data, and I allow people to add meta data
i have a class based on TInterfacedObject. i add it to TTreeNode's Data property.
Add service reference to Amazon service fails, saying Could not load file or assembly

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.