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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:58:03+00:00 2026-05-16T16:58:03+00:00

string xml=< theme> <colors> <color> <code>1</code> <name>blue</name> <priority>5</priority> </color> <color> <code>2</code> <name>red</name> <priority>2</priority> </color>

  • 0
string xml="< theme>

<colors>

<color>
<code>1</code>
<name>blue</name>
<priority>5</priority>
</color>

<color>
<code>2</code>
<name>red</name>
<priority>2</priority>
</color>

<color>
<code>3</code>
<name>green</name>
<priority>7</priority>
</color>

</colors>
</theme>"

I would like to convert this xml string into a List of dictionaries called, say, ‘colors’. For example:

List< Dictionary< string, string>> colors=new List< Dictionary< string, string>>();   
colors=//Magic happens here  

colors[0]["name"] would return 'blue'  
colors[2]["priority"] would return '7'  

etc.

Thanks.

  • 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-16T16:58:03+00:00Added an answer on May 16, 2026 at 4:58 pm

    Assuming you’re using LINQ to XML, that’s relatively easy:

    var query = doc.Descendants("colors")
                   .Elements() // Get to each "color" element
                   .Select(outer => outer.Elements()
                                         .ToDictionary(x => x.Name.LocalName,
                                                       x => x.Value))
                   .ToList();
    

    Let me know if any of that doesn’t make sense to you.

    EDIT: Oops, that would have been a List<Dictionary<XName, string>> before. Fixed 🙂

    EDIT: I note in your comments that you were using fully qualified names. Try it with these using directives:

    using System.Linq;
    using System.Xml.Linq;
    

    They’re required to find the extension methods.

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

Sidebar

Related Questions

given an xml string like this: <some><nested><xml>value</xml></nested></some> what's the best option (using ruby) to
I have a style applied to my whole application: AndroidManifest.xml: <application android:theme=@style/ApplicationStyle android:icon=@drawable/icon android:label=@string/app_name>
I have an xml string such as this: <s:Envelope xmlns:s=http://schemas.xmlsoap.org/soap/envelope/> <s:Body> <ExecuteResponse xmlns=http://schemas.microsoft.com/xrm/2011/Contracts/Services> <ExecuteResult
I've been fighting this all day. Inside my styles.xml file I have color information
My definition XML is: <CheckedTextView android:textSize=18.0dip android:text=@string/text android:textColor=@color/white android:id=@+id/test android:layout_width=fill_parent android:layout_height=wrap_content android:checkMark=?android:attr/textCheckMark /> Everything
Given a valid, arbitrary xmlNodePtr, I would like the string representation of that node,
I have colors in my String.xml file, as shown below: <?xml version=1.0 encoding=utf-8?> <resources>
I have a ListView list that operates nicely. It's set this way: <style name=Theme.Transparent
My persistence.xml looks something like: <persistence-unit name=fruitManager transaction-type=RESOURCE_LOCAL> <!-- Hibernate as provider --> <provider>org.hibernate.ejb.HibernatePersistence</provider>
I added arrays on the string.xml , and these strings are visible in my

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.