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

The Archive Base Latest Questions

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

I have a very simple XML: <Rows> <Row> <id>1</id> <name>foo</name> <more>xyz</more> </Row> <Row> <id>2</id>

  • 0

I have a very simple XML:

<Rows>
  <Row>
    <id>1</id>
    <name>foo</name>
    <more>xyz</more>
  </Row>
  <Row>
    <id>2</id>
    <name>bar</name>
    <more>abc</more>
  </Row>
</Rows>

and need to do lots of querying on the ID, speed being really key.

Would it be more efficient loading the XML into a datatable and creating a PK on id and doing the querying on the data table?

or
Is this the most efficient Linq/Xml code?

myRows = XDocument.Parse(xmlString);               
result = myRows.Element("Rows").Elements("Row").Single(r => r.Element("id").Value == "1");
if (result != null)
    string name = result.Element("name").Value;

Edited For clarity: There are more elements than id & name.

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

    Load it into a Dictionary<int, string>, assuming the id field is unique and an int:

    var myRows = XDocument.Parse(xmlString);
    var myDictionaryOfRows = myRows
        .Descendants("Row")
        .ToDictionary(e => int.Parse(e.Element("id").Value), 
            e => e.Element("name").Value);
    Console.WriteLine(myDictionaryOfRows[1]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some very simple XML: <properties> <property> <name>BobFish</name> <explaination>Bob is a fish.</explaination> </property>
I have a very simple XML datasource structured like this: <datasource> <row> <column>Some text
I have a map that reads an XML file; it's all very simple and
I have the following very simple XML file and I want to quickly parse
i have this very simple download page to get an xml file. the script
I have this very simple python code to read xml for the wikipedia api:
I have very simple persistance.xml file: <?xml version=1.0 encoding=UTF-8?> <persistence version=1.0 xmlns=http://java.sun.com/xml/ns/persistence xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://java.sun.com/xml/ns/persistence
I have a very simple xml content videolar.xml . Flash player takes these elements
I have very simple XML in a string that I'm trying to load via
I have a very simple iFrame with src attribute pointing directly to an xml

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.